[Haskell-cafe] Re: data vs newtype
ChrisK
haskell at list.mightyreason.com
Tue Dec 18 05:23:17 EST 2007
Jonathan Cast wrote:
> So there is a program (or, rather, type) you can write with newtype that
> can't be written with data:
>
> newtype T = T T
That compiles, and anything of type T is ⊥. But it breaks my mental model of
what the compiler does for newtypes. I always think of them as differently
typed versions that share the same underlying "data" declaration and
representation; and then the compiler erases the type information.
So let me think about this one. Looking at the Haskell 98 Report
http://www.haskell.org/onlinereport/decls.html#sect4.2.3
"A declaration of the form
newtype cx => T u1 ... uk = N t
introduces a new type whose representation is the same as an existing type. The
type (T u1 ... uk) renames the datatype t. It differs from a type synonym in
that it creates a distinct type that must be explicitly coerced to or from the
original type"
What I don't see is anything that discusses what "newtype T = T T" could mean.
Is there any difference in how GHC treats "newtype T = T T" versus "data T"?
--
Chris
More information about the Haskell-Cafe
mailing list