
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. Yet this function reminds me how little I know so I have a question for you. I didn't took any lectures in Category Theory (for I'm still just a student, and I won't for there are none in my institute), but are there any good (e)books you would recommend for a (future) computer scientist? Regards Christopher Skrzętnicki

On 2 mar 2008, at 01.21, Krzysztof Skrzętnicki wrote:
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.
Yet this function reminds me how little I know so I have a question for you. I didn't took any lectures in Category Theory (for I'm still just a student, and I won't for there are none in my institute), but are there any good (e)books you would recommend for a (future) computer scientist?
For your particular problem you might want to start with this thread (and the linked paper): http://lambda-the-ultimate.org/node/2003

* Krzysztof Skrzętnicki
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...

2008/3/2 Roman Cheplyaka
* Krzysztof Skrzętnicki
[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)
That's a hack. This is my favorite: type Maybe a = forall b. (a -> b) -> b -> b just x = \j n -> j x nothing = \j n -> n Luke

On 03/03/2008, at 8:30 AM, Luke Palmer wrote:
2008/3/2 Roman Cheplyaka
: * Krzysztof Skrzętnicki
[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)
That's a hack. This is my favorite:
type Maybe a = forall b. (a -> b) -> b -> b just x = \j n -> j x nothing = \j n -> n
For something slightly different, I've always enjoyed lists (or integer indexed structures) as functions: type List a = Integer -> Maybe a You've got to watch out for non-contiguous lists. It's a good challenge to write head, tail, nil and cons for this type. Then write conversions to/ from normal lists. Bernie.

"Krzysztof Skrzętnicki"
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@cl.cam.ac.uk
participants (6)
-
Bernie Pope
-
Jon Fairbairn
-
Krzysztof Skrzętnicki
-
Luke Palmer
-
Roman Cheplyaka
-
Thomas Schilling