I think Herbert's monadic version of "clunky" is really satisfactory :

>clunky env var1 var2 = fromJust  (do val1 <- lookup var1 env
>                                     val2 <- lookup var2 env
>                                     return (var1 + var2)
>                                  ++
>                                  Just (var1 + var2)


A similar solution which avoids using "Just" and "fromJust" (and with
monad comprehension instead of "do") is:


>clunky env var1 var2 = 
>       fromMaybe (var1 + var2)
>                 [val1 + val2 | val1 <- lookup var1 env
>                              , val2 <- lookup var2 env]

(fromJust and fromMaybe are functions from the standard library Maybe)


Both solutions are obtained without any extension to haskell (1.4)
and I think they are as clear as the guarded-pattern version. 
Does somebody know another illustrative example which cannot be
solved with monadic operators?
 
Guille



Reply via email to