<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html; charset=ISO-8859-1"
 http-equiv="Content-Type">
  <title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
<tt>Assume you have the following type:<br>
<br>
data Type = T { field1 :: String, field2 :: Double }<br>
<br>
... and you want to export the type `Type` and the acessors `field1`
and `field2`, but not the constructor `T`, then you would write:<br>
<br>
module MyModule (<br>
&nbsp;&nbsp;&nbsp; Type(field1, field2)<br>
&nbsp;&nbsp;&nbsp; ) where<br>
<br>
Another way to do this is like so:<br>
<br>
module MyModule (<br>
&nbsp;&nbsp;&nbsp; Type,<br>
&nbsp;&nbsp;&nbsp; field1,<br>
&nbsp;&nbsp;&nbsp; field2<br>
&nbsp;&nbsp;&nbsp; ) where<br>
<br>
That's perfectly legal, too.<br>
<br>
Normally, when you write something like:<br>
<br>
module MyModule (<br>
&nbsp;&nbsp;&nbsp; Type(..)<br>
&nbsp;&nbsp;&nbsp; ) where<br>
<br>
the ".." expands out to:<br>
<br>
module MyModule (<br>
&nbsp;&nbsp;&nbsp; Type(T, field1, field2)<br>
&nbsp;&nbsp;&nbsp; ) where<br>
<br>
All the first solution does is just leave out the T constructor from
those exports.<br>
<br>
On 03/24/2013 09:14 AM, Emmanuel Touzery wrote:</tt>
<blockquote
 cite="mid:CAC42Remd29UtHo8biDJmkTh1qrS-xJ8zD4y7G+97k=_pmOXuOQ@mail.gmail.com"
 type="cite">
  <div dir="ltr">
  <div><tt>hi,<br>
  <br>
&nbsp;i was looking at the response type in http-streams:<br>
  <a moz-do-not-send="true"
 href="http://hackage.haskell.org/packages/archive/http-streams/0.4.0.0/doc/html/Network-Http-Client.html#t:Response">http://hackage.haskell.org/packages/archive/http-streams/0.4.0.0/doc/html/Network-Http-Client.html#t:Response</a><br>
  <br>
&nbsp;I'm used that simply the data type and all its "members" are visible --<br>
the functions to access its contents. But in this case on the HTML<br>
documentation the response type looks like it has no members. And the<br>
author has defined like "public accessors" later in the code:<br>
  <br>
getStatusCode :: Response -&gt; StatusCode<br>
getStatusCode = pStatusCode<br>
  <br>
So I'm not even sure how he achieved that the members are not visible,<br>
the data are exported with (..) as is usually done... And the other
thing is why<br>
would you do that.. You could name the member getStatusCode in the first<br>
place, but then it might increase encapsulation to hide it (depending
on how he<br>
managed to hide the members).. But did you then make<br>
it impossible to deconstruct a Response through pattern matching? That<br>
sounds like a minus... Although pattern matching on a data with 6 fields<br>
is always going to be a pain and decreasing the chances for modifying<br>
the data type without breaking compatibility.<br>
  <br>
  </tt></div>
  <div><tt>These "members" are also causing me problems in other
situations, for instance I have some cases when I use a data type only
a few times and with -Wall the compiler tells me I don't use the
accessor; in fact I read that value from the data, but through pattern
matching/deconstruction only, not through that particular function. I'm
thinking to try to hide the warning as I think my code is correct.<br>
  </tt></div>
  <div><tt><br>
Anyway I'm curious on the mechanism used by that library... I've
already noticed a few nice tricks in this library, like a small state
monad to take optional parameters, much more elegant than any other
mechanism i've seen so far to achieve the same effect.<br>
  <br>
  </tt></div>
  <tt>Thank you!<br>
  </tt>
  <div><tt><br>
Emmanuel<br>
  </tt></div>
  </div>
  <pre wrap=""><tt>
</tt><fieldset class="mimeAttachmentHeader"></fieldset><tt>
_______________________________________________
Beginners mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Beginners@haskell.org">Beginners@haskell.org</a>
<a class="moz-txt-link-freetext" href="http://www.haskell.org/mailman/listinfo/beginners">http://www.haskell.org/mailman/listinfo/beginners</a>
</tt></pre>
</blockquote>
<tt><br>
</tt>
</body>
</html>