[Haskell-cafe] newtype is superfluous

Wolfgang Jeltsch wolfgang at jeltsch.net
Sat Oct 15 08:39:21 EDT 2005

Am Samstag, 15. Oktober 2005 08:31 schrieb Bulat Ziganshin:
> Hello Haskell,
>   number of type definition statements in Haskell (data, type, newtype) is
> a bit too large. at least, newtype definition seems to be superfluous - it
> can be replaced by the same `data` definition:
> newtype A = A Int
> and
> data A = A Int
> is equal, excluding for internal representation.

This is not true.  With newtype, A _|_ is _|_, with data, A _|_ is not _|_.  
But as far as I know, the above newtype declaration is equivalent to this:

	data A = A !Int

> [...]

> (moreover, i prefer something like `alias` to defining aliases for
> existing types, and `type` for defining new types, but i think it's a
> bit too late to complain about it :) )

I think that the newtype syntax is misleading.  It suggests a similarity to 
data declarations which is not there.  Take the above newtype declaration.
The expression A n doesn't mean that something new is constructed.  It just 
means a type conversion.  Pattern matching with the pattern A n doesn't mean 
that a part of a data structure is extracted but it just means – a type 
conversion.  So, in my opinion, it would be a lot better if newtype wouldn't 
use these pseudo data constructors.

Best wishes,

More information about the Haskell-Cafe mailing list