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.  Unable to sequence using 'do' operator (Rohit Sharma)
   2. Re:  Unable to sequence using 'do' operator (David McBride)
   3. Re:  Unable to sequence using 'do' operator (Stephen Tetley)
   4. Re:  [Haskell-cafe] [Haskell] ANNOUNCE: Haskell Communities
      and Activities Report (27th ed., November 2014) (Bardur Arantsson)


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

Message: 1
Date: Mon, 17 Nov 2014 23:20:09 +0800
From: Rohit Sharma <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: [Haskell-beginners] Unable to sequence using 'do' operator
Message-ID:
        <CABGHN3Di3+c-+wHXh2W6ZKXq2BaUx9-+aP=-0nmbgs_spes...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

type Parser a = String -> [(a, String)]

Hi,

I am learning haskell and wondering why my definition of firstAndThird does
not work with the do operator, however when i try to use the same using
bind (firstandThird2) it works as expected. I basically want to return a
tuple of first and third character of a string. Can someone please correct
me what i might be overseeing?

I have pasted the same code on codetidy in case if the email lose
formatting.
http://codetidy.com/5726/

Many Thanks,
Rohit

zero :: Parser a
zero = \inp -> []

result :: a -> Parser a
result x = \inp -> [(x, inp)]

item :: Parser Char
item = \inp -> case inp of
                   [] -> []
                   (x:xs) -> [(x,xs)]

bind :: Parser a -> (a -> Parser b) -> Parser b
p `bind` f = \inp -> concat [ ((f x) inp') | (x, inp') <- p inp]

sat :: (Char -> Bool) -> Parser Char
sat predicate = item `bind` (\x -> if predicate x then result x else zero )

lower :: Parser Char
lower = sat (\x -> 'a' <= x && x <= 'z')

firstAndThird :: Parser (Char, Char)
firstAndThird = do x <- item
                        item
                   y <- item
                   return (x,y)

firstAndThird2 :: Parser (Char, Char)
firstAndThird2 = item `bind` \x ->
      item `bind` \y ->
      item  `bind` \z ->
      result (x,z)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20141117/81b605dc/attachment-0001.html>

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

Message: 2
Date: Mon, 17 Nov 2014 10:30:33 -0500
From: David McBride <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Unable to sequence using 'do'
        operator
Message-ID:
        <CAN+Tr43v6oMvYDicfu7rcDYsFaUMz5=zf8yofq2hm2wnafo...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Your indentation is not correct.  Remember that haskell is whitespace
sensitive.

firstAndThird :: Parser (Char, Char)
firstAndThird = do
  x <- item
  item
  y <- item
  return (x,y)

should work.


On Mon, Nov 17, 2014 at 10:20 AM, Rohit Sharma <[email protected]> wrote:

> type Parser a = String -> [(a, String)]
>
> Hi,
>
> I am learning haskell and wondering why my definition of firstAndThird
> does not work with the do operator, however when i try to use the same
> using bind (firstandThird2) it works as expected. I basically want to
> return a tuple of first and third character of a string. Can someone please
> correct me what i might be overseeing?
>
> I have pasted the same code on codetidy in case if the email lose
> formatting.
> http://codetidy.com/5726/
>
> Many Thanks,
> Rohit
>
> zero :: Parser a
> zero = \inp -> []
>
> result :: a -> Parser a
> result x = \inp -> [(x, inp)]
>
> item :: Parser Char
> item = \inp -> case inp of
>                    [] -> []
>                    (x:xs) -> [(x,xs)]
>
> bind :: Parser a -> (a -> Parser b) -> Parser b
> p `bind` f = \inp -> concat [ ((f x) inp') | (x, inp') <- p inp]
>
> sat :: (Char -> Bool) -> Parser Char
> sat predicate = item `bind` (\x -> if predicate x then result x else zero )
>
> lower :: Parser Char
> lower = sat (\x -> 'a' <= x && x <= 'z')
>
> firstAndThird :: Parser (Char, Char)
> firstAndThird = do x <- item
>                         item
>                    y <- item
>                    return (x,y)
>
> firstAndThird2 :: Parser (Char, Char)
> firstAndThird2 = item `bind` \x ->
>       item `bind` \y ->
>       item  `bind` \z ->
>       result (x,z)
>
> _______________________________________________
> 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/20141117/4644208f/attachment-0001.html>

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

Message: 3
Date: Mon, 17 Nov 2014 18:22:34 +0000
From: Stephen Tetley <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Unable to sequence using 'do'
        operator
Message-ID:
        <cab2tprc8m4ydnzzqt2vjdyugbyq89-2orzw5_v1mf+2g1rk...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8

Hi Rohit

It looks like you might be using the parser combinators for Graham
Hutton's book.

Note that the code in the book does not work with standard Haskell as
Graham doesn't want to clutter his presentation with "newtypes". There
is an explanation at the end of the chapter and alternative code on
the website accompanying the book that is written in standard Haskell.

Best wishes

Stephen

On 17 November 2014 15:20, Rohit Sharma <[email protected]> wrote:
> type Parser a = String -> [(a, String)]
>
> Hi,
>
> I am learning haskell and wondering why my definition of firstAndThird does
> not work with the do operator, however when i try to use the same using bind
> (firstandThird2) it works as expected. I basically want to return a tuple of
> first and third character of a string. Can someone please correct me what i
> might be overseeing?
>
> I have pasted the same code on codetidy in case if the email lose
> formatting.
> http://codetidy.com/5726/
>
> Many Thanks,
> Rohit
>
> zero :: Parser a
> zero = \inp -> []
>
> result :: a -> Parser a
> result x = \inp -> [(x, inp)]
>
> item :: Parser Char
> item = \inp -> case inp of
>                    [] -> []
>                    (x:xs) -> [(x,xs)]
>
> bind :: Parser a -> (a -> Parser b) -> Parser b
> p `bind` f = \inp -> concat [ ((f x) inp') | (x, inp') <- p inp]
>
> sat :: (Char -> Bool) -> Parser Char
> sat predicate = item `bind` (\x -> if predicate x then result x else zero )
>
> lower :: Parser Char
> lower = sat (\x -> 'a' <= x && x <= 'z')
>
> firstAndThird :: Parser (Char, Char)
> firstAndThird = do x <- item
>                         item
>                    y <- item
>                    return (x,y)
>
> firstAndThird2 :: Parser (Char, Char)
> firstAndThird2 = item `bind` \x ->
>       item `bind` \y ->
>       item  `bind` \z ->
>       result (x,z)
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>


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

Message: 4
Date: Mon, 17 Nov 2014 20:01:32 +0100
From: Bardur Arantsson <[email protected]>
To: [email protected]
Cc: [email protected], [email protected],
        [email protected]
Subject: Re: [Haskell-beginners] [Haskell-cafe] [Haskell] ANNOUNCE:
        Haskell Communities and Activities Report (27th ed., November 2014)
Message-ID: <[email protected]>
Content-Type: text/plain; charset=utf-8

On 2014-11-17 10:17, Simon Peyton Jones wrote:
> Friends
> 
> With each issue of the Haskell Communities and Activities Report I am freshly 
> awed by the range and creativity of the things you are all doing with 
> Haskell. From web frameworks to bioinformatics, from automatic 
> differentiation to GUIs and games.  Amazing stuff.
> 
> I think we owe the editors, Mihai Maruseac and Alejandro Serrano Mena, a huge 
> debt for putting it together.  Thank you!
> 

Hear, hear!




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

Subject: Digest Footer

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


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

End of Beginners Digest, Vol 77, Issue 17
*****************************************

Reply via email to