
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. we can exclude newtype definition and rely on the assumption that compiler is smart enough to optimize `data` definitions with just one constructor containing one field (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 :) ) -- Best regards, Bulat mailto:bulatz@HotPOP.com

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, Wolfgang

Wolfgang Jeltsch wrote:
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
Alas, Haskell is more subtle than that. Which is why newtype exists. Try case A _|_ of A _ -> 1 with the two versions of A to see the difference. -- Lennart

Hello Lennart, Saturday, October 15, 2005, 5:03:50 PM, you wrote: LA> Alas, Haskell is more subtle than that. Which is why newtype exists. LA> Try LA> case A _|_ of A _ -> 1 LA> with the two versions of A to see the difference. this have practical usage?? may be for such very special things strictness annotation will be enough?? -- Best regards, Bulat mailto:bulatz@HotPOP.com

Wolfgang Jeltsch wrote:
This is not true. With newtype, A _|_ is _|_, with data, A _|_ is not _|_.
It's probably more helpful to explain this in terms of a program that exhibits different behavior in the two cases: case error "data" of A x -> "newtype"
But as far as I know, the above newtype declaration is equivalent to this:
data A = A !Int
Nope: case A (error "data!") of A x -> "data or newtype" -- Ben
participants (4)
-
Ben Rudiak-Gould
-
Bulat Ziganshin
-
Lennart Augustsson
-
Wolfgang Jeltsch