[Haskell-cafe] Question on a common pattern

Tillmann Rendel rendel at informatik.uni-marburg.de
Tue Mar 15 16:39:26 CET 2011


Donn Cave wrote:
>>      someIO>>= f where
>>        f Opt1 = ...
> I like this ... or, I would like it, if I could make it work!
> I get "The last statement in a 'do' construct must be an expression",

Where-clauses can only be used on equations, not on expressions or 
statements, so you would need to float the where clause outwards:

foo = do someIO >>= f
   where f = ...

Or you can use let-in-expressions or let-statements to bind local values 
(or functions) in do-notation:

   do let f = ...
      result <- someIO >>= f


   do result <- let f = ... in
                  someIO >>= Op1 = ..

HTH, Tillmann

More information about the Haskell-Cafe mailing list