(no subject)

John Hughes rjmh@cs.chalmers.se
Fri, 25 Jan 2002 14:20:58 +0100 (MET)


	> Those two constructs are not the same

	> Compare

	> newtype T1 = C1 Bool
	>  data    T2 = C2 !Bool

	As for as I can tell, the only difference in the Report 
	between a newtype and a tuple type with a completely 
	strict constructor is in the rules for pattern matching.  
	So I am trying to find someone who can explain the reason 
	for the difference in the rules!

Right.

	case x of C2 b -> ...

forces x, of course: matching on a datatype is always strict, and a strictness
annotation on a component certainly shouldn't change that.

	case x of b -> ...

does NOT force x: binding something to a variable is lazy.

        case x of C1 b -> ...

does not force x either: the point of newtype is JUST to introduce a new type
isomorphic to, but different from, the old, and therefore the presence or
absence of the newtype constructor should have no effect at all on the
evaluation of the program. Otherwise you couldn't refactor a program to
distinguish between two types previously identified, without potentially
changing its semantics.

Of course this was a design choice, but you can't get away from the fact that
the "natural" matching on T1 is lazy, and on T2 is strict. Given that, I think
it's a cleaner design to have two constructs, than to make do with just data
and settle for "nearly" preserving semantics when making a new type
distinction.

John Hughes