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.  Doubt in let expression (Lakshmi Narasimhan)
   2. Re:  Doubt in let expression (Stephen Tetley)
   3. Re:  Doubt in let expression (Lakshmi Narasimhan)
   4.  When to use ByteString rather than [Char] ... ? (James Fisher)
   5. Re:  When to use ByteString rather than [Char] ...        ?
      (Mukhamed Karanashev)
   6.  Re: When to use ByteString rather than [Char]    ... ?
      (Maciej Piechotka)


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

Message: 1
Date: Sun, 11 Apr 2010 12:42:07 +0530
From: Lakshmi Narasimhan <[email protected]>
Subject: [Haskell-beginners] Doubt in let expression
To: [email protected]
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset="utf-8"

Hello
I am going through Walder's "Monads for Functional Programming" document.
On page 9, there is a piece of code that provides the definition of return
and bind for the State Monad

I have pasted two variations of the code. The first one matches the
definition given in the book.
The second one is what I came up with.

-- State Monad variation
-- Retain the eval function as such
-- Modify M , unit, * definitions


type M a = State->(a, State)
type State = Int

unit  :: a -> M a
unit a = (\e->(a,e))

star :: M a -> (a -> M b) -> M b
m `star` k = (\x -> let (a, aState) = m x in
             let (b, bState) = k a aState in
              (b, bState))


-- State Monad variation -- Retain the eval function as such -- Modify M ,
unit, * definitions type M a = State->(a, State) type State = Int unit :: a
-> M a unit a = (\e->(a,e)) star :: M a -> (a -> M b) -> M b m `star` k =
(\x -> let (a, aState) = m x (b, bState) = k a aState in (b, bState))


In the first definition of star, there are two let statements, while I found
that one let statement would do the work anyway, as done in the second
defintion of start

I am not able to understand if there is any semantic implication in this
syntatic variation of let.

Please help.

Thanks
-- 
Regards
Lakshmi Narasimhan T V
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
http://www.haskell.org/pipermail/beginners/attachments/20100411/c933af2a/attachment-0001.html

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

Message: 2
Date: Sun, 11 Apr 2010 09:28:29 +0100
From: Stephen Tetley <[email protected]>
Subject: Re: [Haskell-beginners] Doubt in let expression
Cc: [email protected]
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1

Hello

There is no semantic implication of the difference.

http://haskell.org/onlinereport/syntax-iso.html

The Haskell syntax allows multiple declarations within a single let expression:

exp10    ->      ...
        |       let decls in exp

where decls is a list of declarations, (braces and colons can be
replaced by layout):

decls    ->      { decl1  ; ... ; decln }       

As a let ... in ... is an expression you can choose to write a list of
declarations as nested let instead as you did in the second version.

>From the original description of GHC intermediate form 'core' [1] page
3 shows that GHC chooses to desugar a let expression with a list of
decls into nested singular let expressions, though this might have
changed and also I might be misreading how GHC core distinguishes
recursive let declarations which do appear as lists.

Best wishes

Stephen


[1] An External Representation for the GHC Core Language (DRAFT for GHC5.02)
Andrew Tolmach and the GHC Team

GHC doesn't define Haskell of course...


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

Message: 3
Date: Sun, 11 Apr 2010 16:10:07 +0530
From: Lakshmi Narasimhan <[email protected]>
Subject: Re: [Haskell-beginners] Doubt in let expression
To: Stephen Tetley <[email protected]>
Cc: [email protected]
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset="utf-8"

Thanks Stephen, that helps.

On Sun, Apr 11, 2010 at 1:58 PM, Stephen Tetley <[email protected]>wrote:

> Hello
>
> There is no semantic implication of the difference.
>
> http://haskell.org/onlinereport/syntax-iso.html
>
> The Haskell syntax allows multiple declarations within a single let
> expression:
>
> exp10    ->      ...
>        |       let decls in exp
>
> where decls is a list of declarations, (braces and colons can be
> replaced by layout):
>
> decls    ->      { decl1  ; ... ; decln }
>
> As a let ... in ... is an expression you can choose to write a list of
> declarations as nested let instead as you did in the second version.
>
> >From the original description of GHC intermediate form 'core' [1] page
> 3 shows that GHC chooses to desugar a let expression with a list of
> decls into nested singular let expressions, though this might have
> changed and also I might be misreading how GHC core distinguishes
> recursive let declarations which do appear as lists.
>
> Best wishes
>
> Stephen
>
>
> [1] An External Representation for the GHC Core Language (DRAFT for
> GHC5.02)
> Andrew Tolmach and the GHC Team
>
> GHC doesn't define Haskell of course...
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>



-- 
Regards
Lakshmi Narasimhan T V
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
http://www.haskell.org/pipermail/beginners/attachments/20100411/cfd650ce/attachment-0001.html

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

Message: 4
Date: Sun, 11 Apr 2010 12:07:34 +0100
From: James Fisher <[email protected]>
Subject: [Haskell-beginners] When to use ByteString rather than [Char]
        ... ?
To: [email protected]
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"

Hi,


After working through a few Haskell tutorials, I've come across numerous
recommendations to use the Data.ByteString library rather than standard
[Char], for reasons of "performance".  I'm having trouble swallowing this --
presumably the standard String is default for good reasons.  Nothing has
answered this question: in what case is it better to use [Char]?

Could anyone point me to a good resource showing the differences between how
[Char] and ByteString are implemented, and giving good a heuristic for me to
decide which is better in any one case?


Best,


James Fisher
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
http://www.haskell.org/pipermail/beginners/attachments/20100411/fc9347a8/attachment-0001.html

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

Message: 5
Date: Sun, 11 Apr 2010 16:11:08 +0400
From: Mukhamed Karanashev <[email protected]>
Subject: Re: [Haskell-beginners] When to use ByteString rather than
        [Char] ...      ?
To: James Fisher <[email protected]>
Cc: [email protected]
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"

Hi, James.
Because "String" is represented by the "[Char]", each element of String is
allocated individually. ByteString represents a string in a single array and
hasn't overhead for allocating each char.

I recommend you to read the "Real World Haskell" -
http://book.realworldhaskell.org/read/. There is some notes about
String/ByteString in the Chapter 8 -
http://book.realworldhaskell.org/read/efficient-file-processing-regular-expressions-and-file-name-matching.html

On Sun, Apr 11, 2010 at 3:07 PM, James Fisher <[email protected]>wrote:

> Hi,
>
>
> After working through a few Haskell tutorials, I've come across numerous
> recommendations to use the Data.ByteString library rather than standard
> [Char], for reasons of "performance".  I'm having trouble swallowing this --
> presumably the standard String is default for good reasons.  Nothing has
> answered this question: in what case is it better to use [Char]?
>
> Could anyone point me to a good resource showing the differences between
> how [Char] and ByteString are implemented, and giving good a heuristic for
> me to decide which is better in any one case?
>
>
> Best,
>
>
> James Fisher
>
> _______________________________________________
> 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/20100411/4b259188/attachment-0001.html

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

Message: 6
Date: Sun, 11 Apr 2010 15:08:48 +0200
From: Maciej Piechotka <[email protected]>
Subject: [Haskell-beginners] Re: When to use ByteString rather than
        [Char]  ... ?
To: [email protected]
Message-ID: <1270991328.5565.20.ca...@picard>
Content-Type: text/plain; charset="utf-8"

On Sun, 2010-04-11 at 16:11 +0400, Mukhamed Karanashev wrote:
> Hi, James.
> Because "String" is represented by the "[Char]", each element of
> String is allocated individually. ByteString represents a string in a
> single array and hasn't overhead for allocating each char. 
> 

Hmm. I read somewhere that GHC optimizes it to handle it more as char *
if possible.

Could anyone clarify it?

Regards
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part
Url : 
http://www.haskell.org/pipermail/beginners/attachments/20100411/65f9a063/attachment.bin

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

_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners


End of Beginners Digest, Vol 22, Issue 15
*****************************************

Reply via email to