[Haskell-cafe] Newbie Question on type constructors

Keith Wansbrough Keith.Wansbrough at cl.cam.ac.uk
Tue Nov 2 05:32:10 EST 2004


> > Put the data declaration in a module, export the type, but
> > not the constructor you want to hide:
> > > module Shape (Shape(Square), circle) where
> 
> Since we were talking about 'what can one do with a constructor as compared 
> with a function', it should be mentioned that this also has a disadvantage: 
> you loose pattern matching outside the module. I.e. no longer can say
[..]
> BTW, would it be possible (in principle) to allow constructor export 
> 'read-only', so matching against a constructor is allowed but not 
> constructing a value?

OCaml has this:

http://caml.inria.fr/ocaml/htmlman/manual021.html#htoc99

--KW 8-)
-- 
Keith Wansbrough <kw217 at cl.cam.ac.uk>
http://www.cl.cam.ac.uk/users/kw217/
University of Cambridge Computer Laboratory.



More information about the Haskell-Cafe mailing list