[Haskell-cafe] Re[2]: strict Haskell dialect

Brian Hulley brianh at metamilk.com
Fri Feb 3 20:50:44 EST 2006


John Meacham wrote:
> On Fri, Feb 03, 2006 at 07:33:12PM -0000, Brian Hulley wrote:
>> One question is how to get some kind of "do" notation that would
>> work well in a strict setting.
>> The existing "do" notation makes use of lazyness in so far as the
>> second arg of  >> is only evaluated when needed. Perhaps a new
>> keyword such as "go" could be used to use >>= instead ie:
>
> you can override (>>) in your monad
>
> instance Monad ... where
>         a >> b = a `seq` b `seq` (a >>= \_ -> b)
>         ....
>
> unless I am misunderstanding what you want.
>
>         John

If strictness was the default (eg if the language were ML not Haskell), then 
in

             putStr "hello" >> putStr (show 1)

both args to >> would be evaluated before >> was called. Thus putStr (show 
1) would be evaluated before the combined monad is actually run, which would 
be wasteful if we were using a monad with a >> function that only runs the 
rhs conditionally on the result of the lhs.
If Haskell were a strict language I think an equivalent for the do notation 
would have to lift everything (except the first expression) and use >>= 
instead of >> .

Regards, Brian. 



More information about the Haskell-Cafe mailing list