Casting + eta reduction
simonpj at microsoft.com
Tue Jul 13 10:09:14 EDT 2010
It compiles to
lift f d = f (d `cast` blah)
which seems fine to me. Are you unhappy with that?
From: glasgow-haskell-users-bounces at haskell.org [mailto:glasgow-haskell-users-bounces at haskell.org] On Behalf Of Louis Wasserman
Sent: 09 July 2010 03:30
To: glasgow-haskell-users at haskell.org
Subject: Casting + eta reduction
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.
wasserman.louis at gmail.com<mailto:wasserman.louis at gmail.com>
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Glasgow-haskell-users