Most interesting discussion -- in reading it, I realized that I had a 'hidden agenda' in asking my question (hidden even from myself), and that is: can I put interesting functionality, like precondition checks & data validation, in data constructors? I suspect not, and that's why I tend to write something like the following:
data Shape = Circle Float | Square Float deriving (Eq, Show) circle :: Float -> Shape circle x = if (x <= 0) then error "Bad radius!" else Circle x That's fine, but I don't know how to prevent users from calling "Circle" directly (in some other languages, I could declare the raw constructor to be "private", and, in Haskell, there may be some way for me to hack module exports to hide the raw constructor, but I haven't seen a way to do that). In any event, it might be useful if I could have some pattern to prevent circumvention of initialization code. Advice? -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Ben Rudiak-Gould Sent: Monday, November 01, 2004 11:33 AM To: [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Subject: Re: [Haskell-cafe] Newbie Question on type constructors Finn Wilcox wrote: >On Mon, 1 Nov 2004, Ben Rudiak-Gould wrote: > >>In particular, one cannot write an invert :: (a->b) -> Maybe >>(b->a) which never returns a wrong answer, except for invert = const >>Nothing > >How about: > >invert = undefined > >This never returns an answer at all, so it can't return a wrong one! Sorry, I should have been clearer: my Nothing return was intended to mean "I don't know an answer", not "there is no answer". So my const Nothing is like your undefined, a function which never returns an answer (and thus never returns a wrong one). -- Ben _______________________________________________ Haskell-Cafe mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell-cafe _______________________________________________ Haskell-Cafe mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell-cafe