[Haskell-cafe] Re: coerce (safe!)

Jon Fairbairn jon.fairbairn at cl.cam.ac.uk
Sun Mar 2 04:19:35 EST 2008

"Krzysztof Skrzętnicki" <gtener at gmail.com> writes:

> 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.

You have to remember that types in Haskell all have
undefined as a member (this is an inevitable consequence of
allowing arbitrary recursion). So your coerce is returning
something that is in the type claimed by the result, so
there's nothing shocking about it!

Jón Fairbairn                                 Jon.Fairbairn at cl.cam.ac.uk

More information about the Haskell-Cafe mailing list