Casting + eta reduction

Louis Wasserman wasserman.louis at gmail.com
Thu Jul 8 22:30:23 EDT 2010


Consider

newtype Foo = Foo Int

lift :: (Int -> a) -> Foo -> a
lift f (Foo x) = f x

Now, I'd expect this to compile with -O2 down to something like

lift f = f `cast` (Foo -> a)

but it doesn't.

It seems that GeneralizedNewtypeDeriving assumes that these two things *are*
equivalent, and it just directly casts the class dictionary.  The
implication would be that that GeneralizedNewtypeDeriving gives more
efficient instances than you could *possibly* get if you wrote them by hand,
which is very sad.

Louis Wasserman
wasserman.louis at gmail.com
http://profiles.google.com/wasserman.louis
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/glasgow-haskell-users/attachments/20100708/bfd4bf48/attachment.html


More information about the Glasgow-haskell-users mailing list