newtype pattern matching
David Feuer
David_Feuer@brown.edu
Fri, 25 Jan 2002 17:15:20 -0500
Marcin 'Qrczak' Kowalczyk qrczak@knm.org.pl said:
The side effect of using data with a strict argument
instead of
newtype is that
f' (C2 x) (C2 y) = C2 (f x y)
unexpectedly becomes strict in both arguments, and we
would have
to write
f' x y = C2 (f (case x of C2 x' -> x')
(case y of C2 y' -> y'))
in the general case where we want to preserve strictness
and don't
want to analyze it ourselves. Newtypes allow to use the
convenient
syntax of pattern matching on the lhs.
---------
Surely you could just write
f' ~(C2 x) ~(C2 y) = C2 (f x y)
which makes the laziness explicit. Since you have to
modify the pattern anyway when changing from a type to a
newtype/datatyp., it would seem that the added documentary
value of the explicit lazy patterns is worth the extra
work....
David Feuer
This message has been brought to you by the letter alpha and the number pi.