[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Haskell 1.3 (newtype)
Resent-Message-Id: <199509131449.QAA17987@animal.cs.chalmers.se>
From: Sebastian Hunt <seb@cs.city.ac.uk>
Subject: Re: Haskell 1.3 (newtype)
Date: Wed, 13 Sep 1995 15:47:12 +0100 (BST)
To: wadler@dcs.gla.ac.uk
Old-Resent-From: haskell-request@dcs.gla.ac.uk
Errors-To: haskell-request@dcs.gla.ac.uk
Approved: haskell@dcs.gla.ac.uk
Resent-Date: Wed, 13 Sep 1995 15:47:47 +0100
Resent-From: kh@dcs.gla.ac.uk
Resent-To: haskell-list-dist@dcs.gla.ac.uk
On Wed, 13 Sep 1995 wadler@dcs.gla.ac.uk wrote:
> Well, I'm glad to see I provoked some discussion!
...
> Why should foo evaluate its argument? It sounds to me like
> Lennart is right, and I should not have let Simon lead me astray!
...
> This is assuming I have understood Lennart correctly, and that
>
> foo (Age n) = (n, Age (n+1))
> foo' a = (n, Age (n+1)) where (Age n) = a
>
> are equivalent when Age is declared as a strict datatype. Unlike
> Sebastian or Simon, I believe it would be a disaster if for a newtype
> one had to distinguish these two definitions.
I don't see how these two can be equivalent, unless a special case is
made in the semantics for data types with a single constructor when the
constructor happens to be strict. Consider
data G = F !Int | D Int
f :: G -> Bool
f (D _) = True
f (F _) = False
If Lennart is right about foo, doesn't it follow that
f (D undefined) = True?
In which case, since D is strict, we have
f undefined = f (D undefined) = True
and so, by monotonicity of f, f v = True for all v and, in particular,
f (F e) = True
This can't be right, surely?
Sebastian