A variant on Stephen's solution is to use Haskell's record syntax, which will generate the "destructors" implicitly. This is no easier on your users, but much easier for you to write, depending on the structure of your type.<br>
<br><div class="gmail_quote">On Thu, Apr 8, 2010 at 15:54, Ashish Agarwal <span dir="ltr"><<a href="mailto:agarwal1975@gmail.com">agarwal1975@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
This makes T fully abstract, which is what I'm trying to avoid. Private types provide an intermediate level of abstraction. The real example I have involves defining a type with numerous constructors (or a record with numerous fields), and I'd like to avoid writing all the corresponding destructors. Even if I did do this, it burdens clients of the module by requiring them to use the alternative destructors.<div>
<br></div><div>I think the feature I'm looking for is "guarded constructors", but to my knowledge there is no such thing.<div class="im"><div><br><br><div class="gmail_quote">On Thu, Apr 8, 2010 at 3:42 PM, Stephen Tetley <span dir="ltr"><<a href="mailto:stephen.tetley@gmail.com" target="_blank">stephen.tetley@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi<br>
<br>
I don't think there is a direct equivalence. You can make T an opaque<br>
type using a module where you do not export the constructor. However,<br>
you can't then pattern match on the type so you have to supply a<br>
destructor - here called unT. Any module that imports XYZ only sees<br>
the type T, the 'handmade' constructor makeT and the destructor unT:<br>
<br>
<br>
<br>
module XYZ<br>
(<br>
T, -- this does not export the constructor<br>
unT<br>
makeT<br>
<br>
) where<br>
<br>
data T = PrivateT Int deriving (Eq,Show)<br>
<br>
unT :: T -> Int<br>
unT (PrivateT i) = i<br>
<br>
-- Add any checking you want here...<br>
makeT :: Int -> T<br>
makeT i = PrivateT i<br>
</blockquote></div><br></div></div></div>
<br>_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org">Beginners@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/beginners" target="_blank">http://www.haskell.org/mailman/listinfo/beginners</a><br>
<br></blockquote></div><br><br clear="all"><br>-- <br>mac<br>