
I'd like to have a simple definition of the meanings of 'type' and 'data' and maybe a clarifing example on their use. I've read the Zipper doc on he wiki ,but I can't make it work on n-ary trees,and most of all they are not any clear the performance hits on using more complex 'data' Thanks Paolino

On Sat, 3 Jul 2004, paolo veronelli wrote:
I'd like to have a simple definition of the meanings of 'type' and 'data' and maybe a clarifing example on their use. (snip)
The way I see it, you use "type" for genuine synonyms where you don't care about the distinction, "newtype" where you want to make a separate type with a single constructor, and "data" where you want to make a separate type with multiple constructors. My memory might be failing, though. -- Mark

Mark Carroll writes:
The way I see it, you use "type" for genuine synonyms where you don't care about the distinction, "newtype" where you want to make a separate type with a single constructor, and "data" where you want to make a separate type with multiple constructors. My memory might be failing, though.
Also, data constructors declared with "newtype" can only take one
argument.
I was going to ask what the difference was between, for example:
newtype Nat1 = Nat1 Int
data Nat2 = Nat2 Int
but I found a section in the Haskell Report that addresses it. [1]
Essentially, (Nat1 undefined) is equivalent to undefined, but (Nat2
undefined) is not. On the other hand, given:
data Nat3 = Nat3 !Int
f1 (Nat1 i) = 42
f2 (Nat2 i) = 42
f3 (Nat3 i) = 42
(f2 undefined) and (f3 undefined) are undefined, but (f1 undefined) =
42. On the other hand, (f1 (Nat1 undefined)) = 42 and (f2 (Nat2
undefined)) = 42, but (f3 (Nat3 undefined)) is undefined.
On the other hand, I can't think of a situation where you would want to
use Nat2 or Nat3 instead of Nat1.
[1] http://www.haskell.org/onlinereport/decls.html#datatype-renaming
--
David Menendez
participants (3)
-
David Menendez
-
Mark Carroll
-
paolo veronelli