Data constructors and pattern matching

David Feuer
Tue, 19 Feb 2002 18:24:09 -0500

It seems to me that it might be very useful for a module to export the
pattern matching operators for a datatype without exporting the
constructors.  Suppose we have

data A = X {a::Int, b::Float}

And we want to maintain the invariant that b is a floating-point
representation of a.  So normally we would have to use a completely
abstract datatype, and provide constructors and destructors.  But in
this case, it would actually make sense to provide the pattern-matching
operator X, but not the data constructor X.  So I think it would be good
to separate these in the module export syntax.

Note:  You can get this with views, but it's more clunky that way.

David Feuer