A variant on Stephen&#39;s solution is to use Haskell&#39;s record syntax, which will generate the &quot;destructors&quot; 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">&lt;<a href="mailto:agarwal1975@gmail.com">agarwal1975@gmail.com</a>&gt;</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&#39;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&#39;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&#39;m looking for is &quot;guarded constructors&quot;, 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">&lt;<a href="mailto:stephen.tetley@gmail.com" target="_blank">stephen.tetley@gmail.com</a>&gt;</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&#39;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&#39;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 &#39;handmade&#39; 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 -&gt; Int<br>
unT (PrivateT i) = i<br>
<br>
-- Add any checking you want here...<br>
makeT :: Int -&gt; 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>