<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<a class="moz-txt-link-freetext" href="https://gist.github.com/tonymorris/a0e82e603d4d32597bbc/revisions">https://gist.github.com/tonymorris/a0e82e603d4d32597bbc/revisions</a><br>
<br>
<div class="moz-cite-prefix">On 06/08/14 06:42, David McBride wrote:<br>
</div>
<blockquote
cite="mid:CAN+Tr42M49dxkKYR78o-OG3=Qr=Din5X-MGwaYLnCMvkvAAwhA@mail.gmail.com"
type="cite">
<div dir="ltr">
<div>
<div>
<div>
<div>
<div>
<div>
<div>I took a look at your main and made some
changes that might help. I have not looked at
your glob file at all.<br>
<br>
</div>
1. Rather than using length args successively in
multiple if/else if statements, which recalculates
the value, just use a case, calculate it once and
then go from there, when you can.<br>
<br>
</div>
2. Use let or where to make new function rather than
putting them all inline.<br>
<br>
</div>
3. Instead of looping the main entirely to get all of
stdin, use said new function and have it loop itself.
You could also streamline this to have its own function
that does not require the glob to be passed into each
loop.<br>
<br>
</div>
4. Use withFile instead of opening the file and then
forgetting about the handle. If you had enough files on
the commandline, you would exhaust the allowable open file
handles on the system. Withfile will close the handle
when you are done with each one.<br>
<br>
</div>
5. Use mapM_ to get rid of the results that are returned by
mapM. It is also faster if you are not going to use the
results anyways.<br>
<br>
</div>
6. When you are in a monad (such as IO), you can use when
instead of if to optionally perform a statement, and it looks
a bit prettier.<br>
<br>
</div>
<div>There are other minor things, but this is a pretty good
start.<br>
</div>
<div><br>
</div>
Here's the resulting code (I have not run it, but it should be
pretty close to what you had): <a moz-do-not-send="true"
href="https://gist.github.com/anonymous/615e48004ca2eed82d0a">https://gist.github.com/anonymous/615e48004ca2eed82d0a</a><br>
</div>
<div class="gmail_extra"><br>
<br>
<div class="gmail_quote">On Tue, Aug 5, 2014 at 4:08 PM, Dominik
Bollmann <span dir="ltr"><<a moz-do-not-send="true"
href="mailto:dominikbollmann@gmail.com" target="_blank">dominikbollmann@gmail.com</a>></span>
wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0
.8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
Hello Haskeller's,<br>
<br>
I recently dived into Haskell and then wanted to practice it
a bit!<br>
Therefore I wrote a small program that matches UNIX-style
globs. The<br>
program behaves kind of like grep, just that it matches a
glob and not a<br>
regular expression. And also, it offers only *very*
rudimental<br>
functionality compared to grep.<br>
<br>
The code is available on github: <a moz-do-not-send="true"
href="https://github.com/bollmann/Globber" target="_blank">https://github.com/bollmann/Globber</a><br>
When writing the program I tried to satisfy the
specification as given<br>
at: <a moz-do-not-send="true"
href="http://www.scs.stanford.edu/14sp-cs240h/labs/lab1.html"
target="_blank">http://www.scs.stanford.edu/14sp-cs240h/labs/lab1.html</a>.
This Lab<br>
material btw. also inspired me to try writing such a program
:-).<br>
<br>
In order to improve my programming in Haskell, I would love
to hear<br>
feedback from you guys on this first small project of mine.
Any comments<br>
regarding style, used idioms, as well as general and
specific code<br>
improvements are highly appreciated. Thanks!<br>
<br>
Cheers, Dominik.<br>
_______________________________________________<br>
Beginners mailing list<br>
<a moz-do-not-send="true"
href="mailto:Beginners@haskell.org">Beginners@haskell.org</a><br>
<a moz-do-not-send="true"
href="http://www.haskell.org/mailman/listinfo/beginners"
target="_blank">http://www.haskell.org/mailman/listinfo/beginners</a><br>
</blockquote>
</div>
<br>
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">_______________________________________________
Beginners mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Beginners@haskell.org">Beginners@haskell.org</a>
<a class="moz-txt-link-freetext" href="http://www.haskell.org/mailman/listinfo/beginners">http://www.haskell.org/mailman/listinfo/beginners</a>
</pre>
</blockquote>
<br>
</body>
</html>