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.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.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.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.2. Use let or where to make new function rather than putting them all inline.I took a look at your main and made some changes that might help. I have not looked at your glob file at all.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.
There are other minor things, but this is a pretty good start.
Here's the resulting code (I have not run it, but it should be pretty close to what you had): https://gist.github.com/anonymous/615e48004ca2eed82d0a
On Tue, Aug 5, 2014 at 4:08 PM, Dominik Bollmann <dominikbollmann@gmail.com> wrote:
Hello Haskeller's,
I recently dived into Haskell and then wanted to practice it a bit!
Therefore I wrote a small program that matches UNIX-style globs. The
program behaves kind of like grep, just that it matches a glob and not a
regular expression. And also, it offers only *very* rudimental
functionality compared to grep.
The code is available on github: https://github.com/bollmann/Globber
When writing the program I tried to satisfy the specification as given
at: http://www.scs.stanford.edu/14sp-cs240h/labs/lab1.html. This Lab
material btw. also inspired me to try writing such a program :-).
In order to improve my programming in Haskell, I would love to hear
feedback from you guys on this first small project of mine. Any comments
regarding style, used idioms, as well as general and specific code
improvements are highly appreciated. Thanks!
Cheers, Dominik.
_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://www.haskell.org/mailman/listinfo/beginners
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners