[Haskell-cafe] Code critique - Was [Maybe Int] sans Nothings

Henning Thielemann schlepptop at henning-thielemann.de
Wed May 25 09:41:49 CEST 2011


Alexander Solla schrieb:

>     buildMap :: GeneratorState1 (Map Prefix [String])
>     buildMap = do (mp,(pfx1,pfx2),words) <- get
>                   if (Prelude.null words)
>                     then {- No more words. Return final map (adding
>     non_word for final prefix). -}
>                       return (insertWithKey' f (pfx1,pfx2) [non_word] mp)
>                     else do {- Add word to map at prefix & continue. -}
>                       put (insertWithKey' f (pfx1,pfx2) [head words] mp,
>     (pfx2,(head words)), tail words)
>                       buildMap
> 
>>>> I'm not a fan of explicit if-then-else's, but my preferred

case words of
   [] -> {- no more words -} ...
   w:ws -> ...

would work perfectly.




More information about the Haskell-Cafe mailing list