On Wed, 06 Jun 2007 09:29:09 -0700, Dmitri O.Kondratiev
<[EMAIL PROTECTED]> wrote:
Default 'fail' implementation in Monad class will be:
*DivBy> divBy 5 0
Loading package haskell98-1.0 ... linking ... done.
*** Exception: user error (div by zero)
And when explicitly defining monad as Maybe it will be different:
*DivBy> divBy 5 0::Maybe Int
Nothing
I am curious if it is possible to 'cast' divBy to List, Identity, other
monads? How?
It just works, and you already did it for Maybe. Just provide the type:
*Main> divBy 5 0::[Int]
[]
*Main> divBy 5 1::[Int]
[5]
Identity fails with a stack overflow, though (GHC 6.6):
*Main> divBy 5 0::Identity Int
*** Exception: stack overflow
*Main> fail "KK" :: Identity ()
*** Exception: stack overflow
*Main> divBy 5 1::Identity Int
*** Exception: stack overflow
Anyway...
JCAB
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe