<div dir="ltr"><div><div>But then since the library is using (..) that would mean everything is exported?<br><br></div>For instance testing on the Request data:<br><br><a href="http://hackage.haskell.org/packages/archive/http-streams/0.4.0.0/doc/html/src/Network-Http-Types.html#Request">http://hackage.haskell.org/packages/archive/http-streams/0.4.0.0/doc/html/src/Network-Http-Types.html#Request</a><br>
<pre><span class="">module</span> <span class="">Network</span><span class="">.</span><span class="">Http</span><span class="">.</span><span class="">Types</span> <span class="">(</span>
<a name="line-17"></a> <span class="">Request</span><span class="">(</span><span class="">..</span><span class="">)</span><span class="">,</span></pre><pre><span class="">data</span> <span class="">Request</span>
<a name="line-112"></a> <span class="">=</span> <span class="">Request</span> <span class="">{</span>
<a name="line-113"></a> <span class="">qMethod</span> <span class="">::</span> <span class="">!</span><span class="">Method</span><span class="">,</span>
<a name="line-114"></a> <span class="">qHost</span> <span class="">::</span> <span class="">Maybe</span> <span class="">ByteString</span><span class="">,</span>
<a name="line-115"></a> <span class="">qPath</span> <span class="">::</span> <span class="">!</span><span class="">ByteString</span><span class="">,</span>
<a name="line-116"></a> <span class="">qBody</span> <span class="">::</span> <span class="">!</span><span class="">EntityBody</span><span class="">,</span>
<a name="line-117"></a> <span class="">qExpect</span> <span class="">::</span> <span class="">!</span><span class="">ExpectMode</span><span class="">,</span>
<a name="line-118"></a> <span class="">qHeaders</span> <span class="">::</span> <span class="">!</span><span class="">Headers</span>
<a name="line-119"></a> <span class="">}</span></pre><br>----<br>{-# LANGUAGE OverloadedStrings #-}<br><br>import Network.Http.Client<br><br>main = do<br> q <- buildRequest $ do<br> http GET "/"<br>
setAccept "text/html"<br><br> print q<br> print $ qMethod q<br><br>---<br><br>test-hs.hs:11:17: Not in scope: `qMethod'<br><br></div>With regards to what Daniel wrote, I realize my email was confusing. When I was talking about warnings I was talking of another problem entirely, that i probably should not have mentioned in this context.<br>
In that other context I had data declarations for types that I would instanciate only from Data.Aeson parsing from JSON. I would then only use pattern matching on the instances, never call the "accessor functions" by themselves, then I get a warning that they're unused which annoys me. But it's quite unrelated to this mail...<br>
<br>Emmanuel<br><div><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Sun, Mar 24, 2013 at 6:34 PM, Gabriel Gonzalez <span dir="ltr"><<a href="mailto:gabriel439@gmail.com" target="_blank">gabriel439@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><u></u>
<div 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>
Type(field1, field2)<br>
) where<br>
<br>
Another way to do this is like so:<br>
<br>
module MyModule (<br>
Type,<br>
field1,<br>
field2<br>
) where<br>
<br>
That's perfectly legal, too.<br>
<br>
Normally, when you write something like:<br>
<br>
module MyModule (<br>
Type(..)<br>
) where<br>
<br>
the ".." expands out to:<br>
<br>
module MyModule (<br>
Type(T, field1, field2)<br>
) where<br>
<br>
All the first solution does is just leave out the T constructor from
those exports.<div><div class="h5"><br>
<br>
On 03/24/2013 09:14 AM, Emmanuel Touzery wrote:</div></div></tt>
<blockquote type="cite"><div><div class="h5">
<div dir="ltr">
<div><tt>hi,<br>
<br>
i was looking at the response type in http-streams:<br>
<a href="http://hackage.haskell.org/packages/archive/http-streams/0.4.0.0/doc/html/Network-Http-Client.html#t:Response" target="_blank">http://hackage.haskell.org/packages/archive/http-streams/0.4.0.0/doc/html/Network-Http-Client.html#t:Response</a><br>
<br>
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 -> 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>
</div></div><pre><tt>
</tt><fieldset></fieldset><tt>
_______________________________________________
Beginners mailing list
<a href="mailto:Beginners@haskell.org" target="_blank">Beginners@haskell.org</a>
<a href="http://www.haskell.org/mailman/listinfo/beginners" target="_blank">http://www.haskell.org/mailman/listinfo/beginners</a>
</tt></pre>
</blockquote>
<tt><br>
</tt>
</div>
</blockquote></div><br></div>