| My question is: how much is this redundancy going to cost? Clearly the
| lambda abstraction is just id, but less obviously (pEmbed (\x->LABEL
| x))is now also id. Presumably none of the Haskell compilers can figure
| this out though? 

It should cost you practically nothing with a compiler at least.  Given 
the decl
        newtype Foo a = MkFoo a

then the expression

        (MkFoo e)

should be exactly as efficient as plain

        e

Similarly, pattern-matching on MkFoo costs nothing.  

We can't guarantee to spot all identities, though.  For example

        map MkFoo xs

still does a "map" and traverses the list, even though (map MkFoo) is
the identity function.

GHC tries fairly hard to make newtype cost very little, but because
it's a new feature I don't have many programs that make heavy use of
newtype, nor comparative measurements of the sort you give.  If you
make the same comparisons with GHC I'd be interested in the results.

Simon



Reply via email to