Send Beginners mailing list submissions to
        beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
        http://www.haskell.org/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
        beginners-requ...@haskell.org

You can reach the person managing the list at
        beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  hiding members of a data,    separate accessors instead
      (Emmanuel Touzery)
   2. Re:  How to design functions so they can be part of other
      larger systems? (Kim-Ee Yeoh)
   3. Re:  stack overflow summing numbers read from a big file
      (Chadda? Fouch?)
   4. Re:  stack overflow summing numbers read from a   big file
      (Axel Wegen)


----------------------------------------------------------------------

Message: 1
Date: Sun, 24 Mar 2013 21:03:54 +0100
From: Emmanuel Touzery <etouz...@gmail.com>
Subject: Re: [Haskell-beginners] hiding members of a data,      separate
        accessors instead
To: "beginners@haskell.org" <beginners@haskell.org>
Message-ID:
        <cac42rekd6wkavrf9eyzqxu6s8k7jhkqlso8ga1rakgptysq...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

Yes, exactly I just was typing a mail on that. I just realized that myself.

And the Network.Http.Types module is not available because the author has
not exported it through cabal.

exposed-modules:   Network.Http.Client
  other-modules:     Network.Http.Types,
                     Network.Http.Connection,
                     Network.Http.RequestBuilder,
                     Network.Http.ResponseParser,
                     Network.Http.Inconvenience


It's the first time I realise that this pattern exists.

So he has effectively returned the data types, but in an opaque way, and
users must use his accessors and pattern matching is impossible.

Thank you!

Emmanuel


On Sun, Mar 24, 2013 at 9:00 PM, Gabriel Gonzalez <gabriel...@gmail.com>wrote:

> **
> On 03/24/2013 12:24 PM, Emmanuel Touzery wrote:
>
>  But then since the library is using (..) that would mean everything is
> exported?
>
>   It only means that those fields are exported from that specific
> module.  Downstream modules that use Network.Http.Types internally may or
> may not re-export everything.
>
> Your example below doesn't import Network.Http.Types; it imports
> Network.Http.Client.  If you look at the source for Network.Http.Client you
> will see that it does not re-export everything it imported from
> Network.Http.Types:
>
>
> http://hackage.haskell.org/packages/archive/http-streams/0.4.0.0/doc/html/src/Network-Http-Client.html
>
> When you import Network.Http.Client, `ghc` only uses whatever is in the
> export list of Network.Http.Client.
>
>  For instance testing on the Request data:
>
>
> http://hackage.haskell.org/packages/archive/http-streams/0.4.0.0/doc/html/src/Network-Http-Types.html#Request
>
> module Network.Http.Types (    Request(..),
>
> data Request    = Request {        qMethod  :: !Method,        qHost    ::  
> Maybe ByteString,        qPath    :: !ByteString,        qBody    :: 
> !EntityBody,        qExpect  :: !ExpectMode,        qHeaders :: !Headers    }
>
>
> ----
> {-# LANGUAGE OverloadedStrings #-}
>
> import Network.Http.Client
>
> main = do
>     q <- buildRequest $ do
>         http GET "/"
>         setAccept "text/html"
>
>     print q
>     print $ qMethod q
>
> ---
>
> test-hs.hs:11:17: Not in scope: `qMethod'
>
>  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.
> 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...
>
> Emmanuel
>
>
>
> On Sun, Mar 24, 2013 at 6:34 PM, Gabriel Gonzalez <gabriel...@gmail.com>wrote:
>
>>  Assume you have the following type:
>>
>> data Type = T { field1 :: String, field2 :: Double }
>>
>> ... and you want to export the type `Type` and the acessors `field1` and
>> `field2`, but not the constructor `T`, then you would write:
>>
>> module MyModule (
>>     Type(field1, field2)
>>     ) where
>>
>> Another way to do this is like so:
>>
>> module MyModule (
>>     Type,
>>     field1,
>>     field2
>>     ) where
>>
>> That's perfectly legal, too.
>>
>> Normally, when you write something like:
>>
>> module MyModule (
>>     Type(..)
>>     ) where
>>
>> the ".." expands out to:
>>
>> module MyModule (
>>     Type(T, field1, field2)
>>     ) where
>>
>> All the first solution does is just leave out the T constructor from
>> those exports.
>>
>>
>> On 03/24/2013 09:14 AM, Emmanuel Touzery wrote:
>>
>>   hi,
>>
>>  i was looking at the response type in http-streams:
>>
>> http://hackage.haskell.org/packages/archive/http-streams/0.4.0.0/doc/html/Network-Http-Client.html#t:Response
>>
>>  I'm used that simply the data type and all its "members" are visible --
>> the functions to access its contents. But in this case on the HTML
>> documentation the response type looks like it has no members. And the
>> author has defined like "public accessors" later in the code:
>>
>> getStatusCode :: Response -> StatusCode
>> getStatusCode = pStatusCode
>>
>> So I'm not even sure how he achieved that the members are not visible,
>> the data are exported with (..) as is usually done... And the other thing
>> is why
>> would you do that.. You could name the member getStatusCode in the first
>> place, but then it might increase encapsulation to hide it (depending on
>> how he
>> managed to hide the members).. But did you then make
>> it impossible to deconstruct a Response through pattern matching? That
>> sounds like a minus... Although pattern matching on a data with 6 fields
>> is always going to be a pain and decreasing the chances for modifying
>> the data type without breaking compatibility.
>>
>>  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.
>>
>> 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.
>>
>>  Thank you!
>>
>> Emmanuel
>>
>>
>> _______________________________________________
>> Beginners mailing 
>> listBeginners@haskell.orghttp://www.haskell.org/mailman/listinfo/beginners
>>
>>
>>
>
> _______________________________________________
> Beginners mailing 
> listBeginners@haskell.orghttp://www.haskell.org/mailman/listinfo/beginners
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20130324/4362bffc/attachment-0001.htm>

------------------------------

Message: 2
Date: Mon, 25 Mar 2013 07:01:47 +0700
From: Kim-Ee Yeoh <k...@atamo.com>
Subject: Re: [Haskell-beginners] How to design functions so they can
        be part of other larger systems?
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Message-ID:
        <CAPY+ZdS8Lv2LsJrn=QAKXEct9wZVZGvb6=i=_w81ekaym6w...@mail.gmail.com>
Content-Type: text/plain; charset=windows-1252

On Mon, Mar 25, 2013 at 12:30 AM, Costello, Roger L. <coste...@mitre.org> wrote:
> How do I design modules so that they may be part of other larger systems? Are 
> there any articles that give guidelines on how to do this? What are your 
> thoughts on how to do this?

For a rare piece of insight, you could start here:

http://lukepalmer.wordpress.com/2010/11/23/encapsulation-considered-harmful/

There's also the following nugget here [1]:

"A language ?is reusable? (to abuse language a bit) if code written in
that language can be easily reused.

This ?obvious? statement is hiding something very important; namely,
reused how? For what? We are in an unfortunate situation in
programming: code is designed to be reused in a particular way, and if
you want to reuse it in a different way you are pretty much out of
luck. An OO widget library is designed for the addition of new types
of widgets, but if you want to reuse a program written in the library
on a new platform you are in for a lot of work. A functional drawing
library is designed so that you can transform and export your drawings
in an open-ended variety of ways, composing new ways out of old ones;
but if you need to draw a circle you have to build it out of lines,
even if there is a much better way to draw a circle on your target.
(This is essentially the expression problem)."

Many Haskellers take after Knuth: "I also must confess to a strong
bias against the fashion for reusable code. To me, ?re-editable code?
is much, much better than an untouchable black box or toolkit."

Hence the proliferation of similar packages on Hackage.

[1] 
http://lukepalmer.wordpress.com/2011/09/15/my-paradigm-is-better-than-your-paradigm/

-- Kim-Ee



------------------------------

Message: 3
Date: Mon, 25 Mar 2013 10:30:50 +0100
From: Chadda? Fouch? <chaddai.fou...@gmail.com>
Subject: Re: [Haskell-beginners] stack overflow summing numbers read
        from a big file
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Message-ID:
        <canfjzryj4u8vdz9jbafoxb863zjy8qtbojrbaakqyhu4w5t...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

On Sun, Mar 24, 2013 at 9:04 PM, Axel Wegen <axel.we...@gmail.com> wrote:

> mukesh tiwari <mukeshtiwari.ii...@gmail.com> writes:
> > It seems like the sum function is causing the stack overflow[1].
> Graham Gill <math.simp...@gmail.com> writes:
> > I think the problem is with laziness in the accumulator of "sum".
> > The prelude "sum" is defined as
>
> `Real World Haskell' actually has a warning regarding the use of
> Prelude's foldl, the space leaks in causes and how to force evaluation
> using `seq' in Chapter 4 under the headings `Left Folds, Laziness, and
> Space Leaks' and `Avoiding Space Leaks with seq'. It just slipped my
> mind, and I had the wrong assumption of the `sum' function.
>
>
Well actually, you wouldn't run into this problem if you compiled with
optimization options (ghc -O2 -o sumFile sumFile.hs) since the strictness
analyzer is pretty good at spotting strict sums.

-- 
Jeda?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20130325/d1aa57fe/attachment-0001.htm>

------------------------------

Message: 4
Date: Mon, 25 Mar 2013 11:04:07 +0000
From: Axel Wegen <axel.we...@gmail.com>
Subject: Re: [Haskell-beginners] stack overflow summing numbers read
        from a  big file
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Message-ID: <87obe7kafs....@lapfel.fritz.box>
Content-Type: text/plain; charset=utf-8

Chadda? Fouch? <chaddai.fou...@gmail.com> writes:
> Well actually, you wouldn't run into this problem if you compiled with
> optimization options (ghc -O2 -o sumFile sumFile.hs) since the
> strictness analyzer is pretty good at spotting strict sums.
Yeah you are right. The strictness analyzer was also mentioned in one of
the links[1]. Had tried compiling with -O after reading it and it worked
also, just forgot to mention it. Thanks for pointing it out.

[1] http://www.haskell.org/haskellwiki/Performance/Strictness
-- 
Axel Wegen



------------------------------

_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://www.haskell.org/mailman/listinfo/beginners


End of Beginners Digest, Vol 57, Issue 36
*****************************************

Reply via email to