[Haskell-cafe] Why is this strict in its arguments?
jules at jellybean.co.uk
Thu Dec 6 05:04:19 EST 2007
Alistair Bayley wrote:
> Nested Maybe cases put me in mind of the Maybe monad. Although in this
> case it''s not trivial; we also need to involve the Maybe [a] instance
> of Data.Monoid too (for the mappend function). I do wonder if I'm
> abusing the monadic instances of Maybe though; is this really any
> clearer than Jules' code?
I think the 'right' answer for this case is to drop the maybes and just
use lists, which is what the OP himself realised. I often find that if I
think I want a Monoid instance for Maybe [a], what I really want is to
just use [a]. (Not always of course...).
> (BTW, this has probably come up before, but wouldn't it be a little
> bit nicer if "when" returned mzero rather than () in the "do nothing"
Yes and no. I've wanted your when' once or twice, but the return ()
version is useful too...
More information about the Haskell-Cafe