Send Beginners mailing list submissions to
[email protected]
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
[email protected]
You can reach the person managing the list at
[email protected]
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."
Today's Topics:
1. hiding members of a data, separate accessors instead
(Emmanuel Touzery)
2. How to design functions so they can be part of other larger
systems? (Costello, Roger L.)
3. Re: hiding members of a data, separate accessors instead
(Gabriel Gonzalez)
4. Re: How to design functions so they can be part of other
larger systems? (Gabriel Gonzalez)
5. Re: hiding members of a data, separate accessors instead
(Daniel Trstenjak)
6. Re: stack overflow summing numbers read from a big file
(Axel Wegen)
----------------------------------------------------------------------
Message: 1
Date: Sun, 24 Mar 2013 17:14:11 +0100
From: Emmanuel Touzery <[email protected]>
Subject: [Haskell-beginners] hiding members of a data, separate
accessors instead
To: "[email protected]" <[email protected]>
Message-ID:
<CAC42Remd29UtHo8biDJmkTh1qrS-xJ8zD4y7G+97k=_pmox...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20130324/ab8aab46/attachment-0001.htm>
------------------------------
Message: 2
Date: Sun, 24 Mar 2013 17:30:46 +0000
From: "Costello, Roger L." <[email protected]>
Subject: [Haskell-beginners] How to design functions so they can be
part of other larger systems?
To: "[email protected]" <[email protected]>
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="us-ascii"
Hi Folks,
I read this statement by Tim Berners-Lee [1]:
It is not only necessary to make sure your own system
is designed to be made of modular parts. It is also
necessary to realize that your own system, no matter
how big and wonderful it seems now, should always be
designed to be a part of another larger system.
Recently I have been working hard to learn how to better modularize. But now
TBL says that I must do more - I must not only modularize well, but I must also
build the modules so that they can be part of other larger systems.
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?
/Roger
[1] http://www.w3.org/DesignIssues/Principles.html
------------------------------
Message: 3
Date: Sun, 24 Mar 2013 10:34:29 -0700
From: Gabriel Gonzalez <[email protected]>
Subject: Re: [Haskell-beginners] hiding members of a data, separate
accessors instead
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"; Format="flowed"
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 list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20130324/f8147fe6/attachment-0001.htm>
------------------------------
Message: 4
Date: Sun, 24 Mar 2013 10:44:28 -0700
From: Gabriel Gonzalez <[email protected]>
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 <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
On 03/24/2013 10:30 AM, Costello, Roger L. wrote:
> Hi Folks,
>
> I read this statement by Tim Berners-Lee [1]:
>
> It is not only necessary to make sure your own system
> is designed to be made of modular parts. It is also
> necessary to realize that your own system, no matter
> how big and wonderful it seems now, should always be
> designed to be a part of another larger system.
>
> Recently I have been working hard to learn how to better modularize. But now
> TBL says that I must do more - I must not only modularize well, but I must
> also build the modules so that they can be part of other larger systems.
>
> 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?
>
>
I recommend that you read the following post I wrote:
http://www.haskellforall.com/2012/08/the-category-design-pattern.html
It introduces category theory in the context of designing modular and
resuable components. Category theory differentiates itself from other
vague notions of modularity by providing an elegant and precise
definition of what it means for something to be "modular".
> /Roger
>
> [1] http://www.w3.org/DesignIssues/Principles.html
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
------------------------------
Message: 5
Date: Sun, 24 Mar 2013 19:25:34 +0100
From: Daniel Trstenjak <[email protected]>
Subject: Re: [Haskell-beginners] hiding members of a data, separate
accessors instead
To: [email protected]
Message-ID: <20130324182534.GA8232@machine>
Content-Type: text/plain; charset=us-ascii
Hi Emmanuel,
> So I'm not even sure how he achieved that the members are not visible,
> the data are exported with (..) as is usually done...
I don't think that the members are hidden, see Gabriels post, you just
seem to be misinterpreting the compiler warnings.
> 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.
You can use the record syntax also for pattern matching:
someFunc :: Response -> (StatusCode, ByteString)
someFunc Response {pStatusCode = code, pStatusMsg = msg} = (statusCode, msg)
> 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.
A data type defined with record syntax is probably more likely to be
changed at any position, so it's more secure not to pattern match by the
position of the fields.
Greetings,
Daniel
------------------------------
Message: 6
Date: Sun, 24 Mar 2013 20:04:11 +0000
From: Axel Wegen <[email protected]>
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 <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain
mukesh tiwari <[email protected]> writes:
> It seems like the sum function is causing the stack overflow[1].
Graham Gill <[email protected]> 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.
mukesh tiwari <[email protected]> writes:
> import Data.List
> sum' = foldl' (+) 0
An explicit version:
sum' l = sum'' l 0
where
sum'' [] a = a
sum'' (x:xs) a = let intermediate = a + x
in intermediate `seq` sum'' xs intermediate
Graham Gill <[email protected]> writes:
> mysum xs = sum' xs 0
> where sum' [] a = a
> sum' (x:xs) !a = sum' xs (x + a)
All three versions work. foldl' uses `seq' to force evaluation and
therefore strictness and the `BangPatterns' are a nice syntactic feature
to express strictness, because the excessive use of `seq' can make code
unwieldy. At least that is as far as my not fully correct understanding
goes for now.
> http://www.haskell.org/haskellwiki/Memory_leak
> http://www.haskell.org/haskellwiki/Performance/Strictness
Anyway I just wanted to thank you for helping me solve my problem, for
the helpful links and slightly improving my understanding of Haskell's
laziness. Long way to go.
--
Axel Wegen
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 57, Issue 34
*****************************************