[Haskell-beginners] code review

Henk-Jan van Tuyl hjgtuyl at chello.nl
Mon Apr 8 15:17:37 CEST 2013


On Fri, 05 Apr 2013 07:49:01 +0200, Chris Bolton <c at chrisbolton.me> wrote:

> Just a little code review if anyone has the time :)
>
> http://codereview.stackexchange.com/questions/24741/simple-in-memory-db

It is considered good practice to write the type of all top level  
functions, for documentation purposes and for better compiler error  
messages.

Change:
   cmdKey c   = let Just s = key   c in s
   cmdValue c = let Just s = value c in s
to:
   cmdKey c   = fromJust $ key   c
   cmdValue c = fromJust $ value c
or:
   cmdKey    = fromJust . key
   cmdValue  = fromJust . value
Note, that your program will crash if you try to evaluate
   cmdValue Nothing
; there a function fromMaybe that allows you to specify a default value  
for this case.

You can simplify:
     end = case name of
               "end" -> True
               _     -> False
to:
     end = name == "end"

Regards,
Henk-Jan van Tuyl


-- 
http://Van.Tuyl.eu/
http://members.chello.nl/hjgtuyl/tourdemonad.html
Haskell programming
--



More information about the Beginners mailing list