If newtype = data !, then why use does Haskell' need newtype

Tim Chevalier catamorphism at gmail.com
Thu Oct 11 18:26:57 EDT 2007


On 10/11/07, Dan Weston <westondan at imageworks.com> wrote:
> I presume that the two statements below are equivalent [1]:
>
> newtype A = MkA  Int
> data    A = MkA !Int
>
> So does Haskell' still need newtype? It seems like a needless keyword.
>

newtype and data have different semantics: Haskell guarantees that an
A will have the exact same run-time representation as an Int, if A is
declared with the newtype as above. It doesn't guarantee that if you
use data instead of newtype. It may be that GHC compiles code in the
same way with either of your type declarations above, but that's an
implementation-dependent choice.

Cheers,
Tim

-- 
Tim Chevalier * catamorphism.org * Often in error, never in doubt
"in a recent future, this is past" -- James Keelaghan


More information about the Haskell-prime mailing list