[Haskell-cafe] coerce (safe!)

Roman Cheplyaka roma at ro-che.info
Sun Mar 2 03:49:37 EST 2008

* Krzysztof Skrzętnicki <gtener at gmail.com> [2008-03-02 01:21:42+0100]
> Well, it is simply
> > coerce :: a -> b
> > coerce _ = undefined
> so coerce is simply empty function. But still, it is possible to write a
> function of type (a->b).
> Well, possibly I didn't write anything particularly new, but please excuse
> me for I'm still in
> sort of a shock after I've discovered it.

Also there's nice possibility of defining Maybe a without ADT.
type Maybe a = (a, Bool)
just x = (x, True)
nothing = (undefined, False)

Roman I. Cheplyaka :: http://ro-che.info/
...being in love is totally punk rock...
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 307 bytes
Desc: Digital signature
Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20080302/b1901cd9/attachment.bin

More information about the Haskell-Cafe mailing list