On 17 Dec 2007, [EMAIL PROTECTED] wrote:

> Ooo
>
> "The constructor of a newtype must have exactly one field but `R' has
> two In the newtype declaration for `Rectangle'"
>
> It doesn't like 
>
> "newtype Rectangle = R Int Int"

You want

  data Rectangle = R Int Int

A newtype declaration will be completely erased at compile time.  That
is, when you have a declaration like

  newtype Circle = C Int

the compiled code will not be able to distinguish between a Circle and
an Int.  You do, however, get all the benefits of a separate entity in
the type system.  When your type only has one constructor, newtype is
preferred over data, but they are semantically equivalent.  There are
extensions which provide impressive newtype-deriving-foo (getting the
compiler to write fairly non-trivial instance declarations for you).

Jed

Attachment: pgp595ILQHSg7.pgp
Description: PGP signature

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to