Re: Beginners Digest, Vol 106, Issue 7

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Re: Beginners Digest, Vol 106, Issue 7

Andrey Klaus
Hello everybody,

A small question.
-----
packageP = do
    literal “package"
-----

what is the "literal" in this code? My problem is

$ ghc ParserTest.hs
[1 of 1] Compiling ParserTest       ( ParserTest.hs, ParserTest.o )

ParserTest.hs:11:5: Not in scope: ‘literal’

$ ghc --version
The Glorious Glasgow Haskell Compilation System, version 7.10.3

Is this because I use old version of software?

Thanks,
Andrey



2017-04-14 21:58 GMT+03:00 <[hidden email]>:
Send Beginners mailing list submissions to
        [hidden email]

To subscribe or unsubscribe via the World Wide Web, visit
        http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
        [hidden email]

You can reach the person managing the list at
        [hidden email]

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


Today's Topics:

   1.  Parsing (mike h)
   2. Re:  Parsing (David McBride)
   3. Re:  Parsing (Francesco Ariis)
   4. Re:  Parsing (mike h)
   5. Re:  Parsing (mike h)


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

Message: 1
Date: Fri, 14 Apr 2017 19:02:37 +0100
From: mike h <[hidden email]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[hidden email]>
Subject: [Haskell-beginners] Parsing
Message-ID: <[hidden email]>
Content-Type: text/plain; charset=utf-8

I have
data PackageDec = Pkg String deriving Show

and a parser for it

packageP :: Parser PackageDec
packageP = do
    literal “package"
    x  <- identifier
    xs <- many ((:) <$> char '.' <*> identifier)
    return $ Pkg . concat $ (x:xs)

so I’m parsing for this sort  of string
“package some.sort.of.name

and I’m trying to rewrite the packageP parser in applicative style. As a not quite correct start I have

packageP' :: Parser PackageDec
packageP' = literal "package" >>  Pkg . concat <$> many ((:) <$> char '.' <*> identifier)

but I can’t see how to get the ‘first’ identifier into this sequence - i.e. the bit that corresponds to  x <- identifier        in the
monadic version.

in ghci
λ-> :t many ((:) <$> char '.' <*> identifier)
many ((:) <$> char '.' <*> identifier) :: Parser [[Char]]

so I think that somehow I need to get the ‘first’ identifier into a list just after  Pkg . concat  so that the whole list gets flattened and everybody is happy!

Any help appreciated.

Thanks
Mike







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

Message: 2
Date: Fri, 14 Apr 2017 14:17:42 -0400
From: David McBride <[hidden email]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[hidden email]>
Subject: Re: [Haskell-beginners] Parsing
Message-ID:
        <[hidden email]>
Content-Type: text/plain; charset=UTF-8

Try breaking it up into pieces.  There a literal "package" which is
dropped.  There is a first identifier, then there are the rest of the
identifiers (a list), then those two things are combined somehow (with
:).

literal "package" *> (:) <$> identifier <*> restOfIdentifiers
where
  restOfIdentifiers :: Applicative f => f [String]
  restOfIdentifiers = many ((:) <$> char '.' <*> identifier

I have not tested this code, but it should be close to what you are looking for.

On Fri, Apr 14, 2017 at 2:02 PM, mike h <[hidden email]> wrote:
> I have
> data PackageDec = Pkg String deriving Show
>
> and a parser for it
>
> packageP :: Parser PackageDec
> packageP = do
>     literal “package"
>     x  <- identifier
>     xs <- many ((:) <$> char '.' <*> identifier)
>     return $ Pkg . concat $ (x:xs)
>
> so I’m parsing for this sort  of string
> “package some.sort.of.name
>
> and I’m trying to rewrite the packageP parser in applicative style. As a not quite correct start I have
>
> packageP' :: Parser PackageDec
> packageP' = literal "package" >>  Pkg . concat <$> many ((:) <$> char '.' <*> identifier)
>
> but I can’t see how to get the ‘first’ identifier into this sequence - i.e. the bit that corresponds to  x <- identifier        in the
> monadic version.
>
> in ghci
> λ-> :t many ((:) <$> char '.' <*> identifier)
> many ((:) <$> char '.' <*> identifier) :: Parser [[Char]]
>
> so I think that somehow I need to get the ‘first’ identifier into a list just after  Pkg . concat  so that the whole list gets flattened and everybody is happy!
>
> Any help appreciated.
>
> Thanks
> Mike
>
>
>
>
>
> _______________________________________________
> Beginners mailing list
> [hidden email]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


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

Message: 3
Date: Fri, 14 Apr 2017 20:35:32 +0200
From: Francesco Ariis <[hidden email]>
To: [hidden email]
Subject: Re: [Haskell-beginners] Parsing
Message-ID: <20170414183532.GA4376@casa.casa>
Content-Type: text/plain; charset=utf-8

On Fri, Apr 14, 2017 at 07:02:37PM +0100, mike h wrote:
> I have
> data PackageDec = Pkg String deriving Show
>
> and a parser for it
>
> packageP :: Parser PackageDec
> packageP = do
>     literal “package"
>     x  <- identifier
>     xs <- many ((:) <$> char '.' <*> identifier)
>     return $ Pkg . concat $ (x:xs)
>
> so I’m parsing for this sort  of string
> “package some.sort.of.name
>
> and I’m trying to rewrite the packageP parser in applicative style. As a not quite correct start I have

Hello Mike,

    I am not really sure what you are doing here? You are parsing a dot
separated list (like.this.one) but at the end you are concatenating all
together, why?
Are you sure you are not wanting [String] instead of String?

If so, Parsec comes with some handy parser combinators [1], maybe one of
them could fit your bill:

    -- should work
    packageP = literal "package" *> Pkg <$> sepEndBy1 identifier (char '.')

[1] https://hackage.haskell.org/package/parsec-3.1.11/docs/Text-Parsec-Combinator.html


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

Message: 4
Date: Fri, 14 Apr 2017 20:12:14 +0100
From: mike h <[hidden email]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[hidden email]>
Subject: Re: [Haskell-beginners] Parsing
Message-ID: <[hidden email]>
Content-Type: text/plain; charset=utf-8

Hi David,

Thanks but I tried something like that before I posted. I’ll try again maybe I mistyped.

Mike
> On 14 Apr 2017, at 19:17, David McBride <[hidden email]> wrote:
>
> Try breaking it up into pieces.  There a literal "package" which is
> dropped.  There is a first identifier, then there are the rest of the
> identifiers (a list), then those two things are combined somehow (with
> :).
>
> literal "package" *> (:) <$> identifier <*> restOfIdentifiers
> where
>  restOfIdentifiers :: Applicative f => f [String]
>  restOfIdentifiers = many ((:) <$> char '.' <*> identifier
>
> I have not tested this code, but it should be close to what you are looking for.
>
> On Fri, Apr 14, 2017 at 2:02 PM, mike h <[hidden email]> wrote:
>> I have
>> data PackageDec = Pkg String deriving Show
>>
>> and a parser for it
>>
>> packageP :: Parser PackageDec
>> packageP = do
>>    literal “package"
>>    x  <- identifier
>>    xs <- many ((:) <$> char '.' <*> identifier)
>>    return $ Pkg . concat $ (x:xs)
>>
>> so I’m parsing for this sort  of string
>> “package some.sort.of.name
>>
>> and I’m trying to rewrite the packageP parser in applicative style. As a not quite correct start I have
>>
>> packageP' :: Parser PackageDec
>> packageP' = literal "package" >>  Pkg . concat <$> many ((:) <$> char '.' <*> identifier)
>>
>> but I can’t see how to get the ‘first’ identifier into this sequence - i.e. the bit that corresponds to  x <- identifier        in the
>> monadic version.
>>
>> in ghci
>> λ-> :t many ((:) <$> char '.' <*> identifier)
>> many ((:) <$> char '.' <*> identifier) :: Parser [[Char]]
>>
>> so I think that somehow I need to get the ‘first’ identifier into a list just after  Pkg . concat  so that the whole list gets flattened and everybody is happy!
>>
>> Any help appreciated.
>>
>> Thanks
>> Mike
>>
>>
>>
>>
>>
>> _______________________________________________
>> Beginners mailing list
>> [hidden email]
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
> _______________________________________________
> Beginners mailing list
> [hidden email]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners



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

Message: 5
Date: Fri, 14 Apr 2017 20:19:40 +0100
From: mike h <[hidden email]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[hidden email]>
Subject: Re: [Haskell-beginners] Parsing
Message-ID: <[hidden email]>
Content-Type: text/plain; charset="utf-8"

Hi Francesco,
Yes, I think you are right with "Are you sure you are not wanting [String] instead of String?”

I could use Parsec but I’m building up a parser library from first principles i.e.

newtype Parser a = P (String -> [(a,String)])

parse :: Parser a -> String -> [(a,String)]
parse (P p)  = p

and so on….

It’s just an exercise to see how far I can get. And its good fun. So maybe I need add another combinator or to what I already have.

Thanks

Mike


> On 14 Apr 2017, at 19:35, Francesco Ariis <[hidden email]> wrote:
>
> On Fri, Apr 14, 2017 at 07:02:37PM +0100, mike h wrote:
>> I have
>> data PackageDec = Pkg String deriving Show
>>
>> and a parser for it
>>
>> packageP :: Parser PackageDec
>> packageP = do
>>    literal “package"
>>    x  <- identifier
>>    xs <- many ((:) <$> char '.' <*> identifier)
>>    return $ Pkg . concat $ (x:xs)
>>
>> so I’m parsing for this sort  of string
>> “package some.sort.of.name
>>
>> and I’m trying to rewrite the packageP parser in applicative style. As a not quite correct start I have
>
> Hello Mike,
>
>    I am not really sure what you are doing here? You are parsing a dot
> separated list (like.this.one) but at the end you are concatenating all
> together, why?
> Are you sure you are not wanting [String] instead of String?
>
> If so, Parsec comes with some handy parser combinators [1], maybe one of
> them could fit your bill:
>
>    -- should work
>    packageP = literal "package" *> Pkg <$> sepEndBy1 identifier (char '.')
>
> [1] https://hackage.haskell.org/package/parsec-3.1.11/docs/Text-Parsec-Combinator.html <https://hackage.haskell.org/package/parsec-3.1.11/docs/Text-Parsec-Combinator.html>
> _______________________________________________
> Beginners mailing list
> [hidden email] <mailto:[hidden email]>
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners <http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20170414/66a17133/attachment.html>

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

Subject: Digest Footer

_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


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

End of Beginners Digest, Vol 106, Issue 7
*****************************************


_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Beginners Digest, Vol 106, Issue 7

Francesco Ariis
On Tue, Apr 18, 2017 at 03:39:28PM +0300, Andrey Klaus wrote:

> Hello everybody,
>
> A small question.
> -----
> packageP = do
>     literal “package"
> -----
>
> what is the "literal" in this code? My problem is
>
> $ ghc ParserTest.hs
> [1 of 1] Compiling ParserTest       ( ParserTest.hs, ParserTest.o )

Hello Andrey,
    literal is not in scope, apparently. Did you forget to put an
import at the top of ParserTest.hs? E.g.:

    import SomeParserModule
_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Beginners Digest, Vol 106, Issue 7

David McBride
In reply to this post by Andrey Klaus
That depends on what package you are using to parse.  If you are using
parsec, you can use the string function from Text.Parsec.Char.  If you
are using some other package, it probably has a different name for it.

On Tue, Apr 18, 2017 at 8:39 AM, Andrey Klaus <[hidden email]> wrote:

> Hello everybody,
>
> A small question.
> -----
> packageP = do
>     literal “package"
> -----
>
> what is the "literal" in this code? My problem is
>
> $ ghc ParserTest.hs
> [1 of 1] Compiling ParserTest       ( ParserTest.hs, ParserTest.o )
>
> ParserTest.hs:11:5: Not in scope: ‘literal’
>
> $ ghc --version
> The Glorious Glasgow Haskell Compilation System, version 7.10.3
>
> Is this because I use old version of software?
>
> Thanks,
> Andrey
>
>
>
> 2017-04-14 21:58 GMT+03:00 <[hidden email]>:
>>
>> Send Beginners mailing list submissions to
>>         [hidden email]
>>
>> To subscribe or unsubscribe via the World Wide Web, visit
>>         http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>> or, via email, send a message with subject or body 'help' to
>>         [hidden email]
>>
>> You can reach the person managing the list at
>>         [hidden email]
>>
>> When replying, please edit your Subject line so it is more specific
>> than "Re: Contents of Beginners digest..."
>>
>>
>> Today's Topics:
>>
>>    1.  Parsing (mike h)
>>    2. Re:  Parsing (David McBride)
>>    3. Re:  Parsing (Francesco Ariis)
>>    4. Re:  Parsing (mike h)
>>    5. Re:  Parsing (mike h)
>>
>>
>> ----------------------------------------------------------------------
>>
>> Message: 1
>> Date: Fri, 14 Apr 2017 19:02:37 +0100
>> From: mike h <[hidden email]>
>> To: The Haskell-Beginners Mailing List - Discussion of primarily
>>         beginner-level topics related to Haskell <[hidden email]>
>> Subject: [Haskell-beginners] Parsing
>> Message-ID: <[hidden email]>
>> Content-Type: text/plain; charset=utf-8
>>
>> I have
>> data PackageDec = Pkg String deriving Show
>>
>> and a parser for it
>>
>> packageP :: Parser PackageDec
>> packageP = do
>>     literal “package"
>>     x  <- identifier
>>     xs <- many ((:) <$> char '.' <*> identifier)
>>     return $ Pkg . concat $ (x:xs)
>>
>> so I’m parsing for this sort  of string
>> “package some.sort.of.name”
>>
>> and I’m trying to rewrite the packageP parser in applicative style. As a
>> not quite correct start I have
>>
>> packageP' :: Parser PackageDec
>> packageP' = literal "package" >>  Pkg . concat <$> many ((:) <$> char '.'
>> <*> identifier)
>>
>> but I can’t see how to get the ‘first’ identifier into this sequence -
>> i.e. the bit that corresponds to  x <- identifier        in the
>> monadic version.
>>
>> in ghci
>> λ-> :t many ((:) <$> char '.' <*> identifier)
>> many ((:) <$> char '.' <*> identifier) :: Parser [[Char]]
>>
>> so I think that somehow I need to get the ‘first’ identifier into a list
>> just after  Pkg . concat  so that the whole list gets flattened and
>> everybody is happy!
>>
>> Any help appreciated.
>>
>> Thanks
>> Mike
>>
>>
>>
>>
>>
>>
>>
>> ------------------------------
>>
>> Message: 2
>> Date: Fri, 14 Apr 2017 14:17:42 -0400
>> From: David McBride <[hidden email]>
>> To: The Haskell-Beginners Mailing List - Discussion of primarily
>>         beginner-level topics related to Haskell <[hidden email]>
>> Subject: Re: [Haskell-beginners] Parsing
>> Message-ID:
>>
>> <[hidden email]>
>> Content-Type: text/plain; charset=UTF-8
>>
>> Try breaking it up into pieces.  There a literal "package" which is
>> dropped.  There is a first identifier, then there are the rest of the
>> identifiers (a list), then those two things are combined somehow (with
>> :).
>>
>> literal "package" *> (:) <$> identifier <*> restOfIdentifiers
>> where
>>   restOfIdentifiers :: Applicative f => f [String]
>>   restOfIdentifiers = many ((:) <$> char '.' <*> identifier
>>
>> I have not tested this code, but it should be close to what you are
>> looking for.
>>
>> On Fri, Apr 14, 2017 at 2:02 PM, mike h <[hidden email]>
>> wrote:
>> > I have
>> > data PackageDec = Pkg String deriving Show
>> >
>> > and a parser for it
>> >
>> > packageP :: Parser PackageDec
>> > packageP = do
>> >     literal “package"
>> >     x  <- identifier
>> >     xs <- many ((:) <$> char '.' <*> identifier)
>> >     return $ Pkg . concat $ (x:xs)
>> >
>> > so I’m parsing for this sort  of string
>> > “package some.sort.of.name”
>> >
>> > and I’m trying to rewrite the packageP parser in applicative style. As a
>> > not quite correct start I have
>> >
>> > packageP' :: Parser PackageDec
>> > packageP' = literal "package" >>  Pkg . concat <$> many ((:) <$> char
>> > '.' <*> identifier)
>> >
>> > but I can’t see how to get the ‘first’ identifier into this sequence -
>> > i.e. the bit that corresponds to  x <- identifier        in the
>> > monadic version.
>> >
>> > in ghci
>> > λ-> :t many ((:) <$> char '.' <*> identifier)
>> > many ((:) <$> char '.' <*> identifier) :: Parser [[Char]]
>> >
>> > so I think that somehow I need to get the ‘first’ identifier into a list
>> > just after  Pkg . concat  so that the whole list gets flattened and
>> > everybody is happy!
>> >
>> > Any help appreciated.
>> >
>> > Thanks
>> > Mike
>> >
>> >
>> >
>> >
>> >
>> > _______________________________________________
>> > Beginners mailing list
>> > [hidden email]
>> > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>>
>>
>> ------------------------------
>>
>> Message: 3
>> Date: Fri, 14 Apr 2017 20:35:32 +0200
>> From: Francesco Ariis <[hidden email]>
>> To: [hidden email]
>> Subject: Re: [Haskell-beginners] Parsing
>> Message-ID: <[hidden email]>
>> Content-Type: text/plain; charset=utf-8
>>
>> On Fri, Apr 14, 2017 at 07:02:37PM +0100, mike h wrote:
>> > I have
>> > data PackageDec = Pkg String deriving Show
>> >
>> > and a parser for it
>> >
>> > packageP :: Parser PackageDec
>> > packageP = do
>> >     literal “package"
>> >     x  <- identifier
>> >     xs <- many ((:) <$> char '.' <*> identifier)
>> >     return $ Pkg . concat $ (x:xs)
>> >
>> > so I’m parsing for this sort  of string
>> > “package some.sort.of.name”
>> >
>> > and I’m trying to rewrite the packageP parser in applicative style. As a
>> > not quite correct start I have
>>
>> Hello Mike,
>>
>>     I am not really sure what you are doing here? You are parsing a dot
>> separated list (like.this.one) but at the end you are concatenating all
>> together, why?
>> Are you sure you are not wanting [String] instead of String?
>>
>> If so, Parsec comes with some handy parser combinators [1], maybe one of
>> them could fit your bill:
>>
>>     -- should work
>>     packageP = literal "package" *> Pkg <$> sepEndBy1 identifier (char
>> '.')
>>
>> [1]
>> https://hackage.haskell.org/package/parsec-3.1.11/docs/Text-Parsec-Combinator.html
>>
>>
>> ------------------------------
>>
>> Message: 4
>> Date: Fri, 14 Apr 2017 20:12:14 +0100
>> From: mike h <[hidden email]>
>> To: The Haskell-Beginners Mailing List - Discussion of primarily
>>         beginner-level topics related to Haskell <[hidden email]>
>> Subject: Re: [Haskell-beginners] Parsing
>> Message-ID: <[hidden email]>
>> Content-Type: text/plain; charset=utf-8
>>
>> Hi David,
>>
>> Thanks but I tried something like that before I posted. I’ll try again
>> maybe I mistyped.
>>
>> Mike
>> > On 14 Apr 2017, at 19:17, David McBride <[hidden email]> wrote:
>> >
>> > Try breaking it up into pieces.  There a literal "package" which is
>> > dropped.  There is a first identifier, then there are the rest of the
>> > identifiers (a list), then those two things are combined somehow (with
>> > :).
>> >
>> > literal "package" *> (:) <$> identifier <*> restOfIdentifiers
>> > where
>> >  restOfIdentifiers :: Applicative f => f [String]
>> >  restOfIdentifiers = many ((:) <$> char '.' <*> identifier
>> >
>> > I have not tested this code, but it should be close to what you are
>> > looking for.
>> >
>> > On Fri, Apr 14, 2017 at 2:02 PM, mike h <[hidden email]>
>> > wrote:
>> >> I have
>> >> data PackageDec = Pkg String deriving Show
>> >>
>> >> and a parser for it
>> >>
>> >> packageP :: Parser PackageDec
>> >> packageP = do
>> >>    literal “package"
>> >>    x  <- identifier
>> >>    xs <- many ((:) <$> char '.' <*> identifier)
>> >>    return $ Pkg . concat $ (x:xs)
>> >>
>> >> so I’m parsing for this sort  of string
>> >> “package some.sort.of.name”
>> >>
>> >> and I’m trying to rewrite the packageP parser in applicative style. As
>> >> a not quite correct start I have
>> >>
>> >> packageP' :: Parser PackageDec
>> >> packageP' = literal "package" >>  Pkg . concat <$> many ((:) <$> char
>> >> '.' <*> identifier)
>> >>
>> >> but I can’t see how to get the ‘first’ identifier into this sequence -
>> >> i.e. the bit that corresponds to  x <- identifier        in the
>> >> monadic version.
>> >>
>> >> in ghci
>> >> λ-> :t many ((:) <$> char '.' <*> identifier)
>> >> many ((:) <$> char '.' <*> identifier) :: Parser [[Char]]
>> >>
>> >> so I think that somehow I need to get the ‘first’ identifier into a
>> >> list just after  Pkg . concat  so that the whole list gets flattened and
>> >> everybody is happy!
>> >>
>> >> Any help appreciated.
>> >>
>> >> Thanks
>> >> Mike
>> >>
>> >>
>> >>
>> >>
>> >>
>> >> _______________________________________________
>> >> Beginners mailing list
>> >> [hidden email]
>> >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>> > _______________________________________________
>> > Beginners mailing list
>> > [hidden email]
>> > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>>
>>
>>
>> ------------------------------
>>
>> Message: 5
>> Date: Fri, 14 Apr 2017 20:19:40 +0100
>> From: mike h <[hidden email]>
>> To: The Haskell-Beginners Mailing List - Discussion of primarily
>>         beginner-level topics related to Haskell <[hidden email]>
>> Subject: Re: [Haskell-beginners] Parsing
>> Message-ID: <[hidden email]>
>> Content-Type: text/plain; charset="utf-8"
>>
>> Hi Francesco,
>> Yes, I think you are right with "Are you sure you are not wanting [String]
>> instead of String?”
>>
>> I could use Parsec but I’m building up a parser library from first
>> principles i.e.
>>
>> newtype Parser a = P (String -> [(a,String)])
>>
>> parse :: Parser a -> String -> [(a,String)]
>> parse (P p)  = p
>>
>> and so on….
>>
>> It’s just an exercise to see how far I can get. And its good fun. So maybe
>> I need add another combinator or to what I already have.
>>
>> Thanks
>>
>> Mike
>>
>>
>> > On 14 Apr 2017, at 19:35, Francesco Ariis <[hidden email]> wrote:
>> >
>> > On Fri, Apr 14, 2017 at 07:02:37PM +0100, mike h wrote:
>> >> I have
>> >> data PackageDec = Pkg String deriving Show
>> >>
>> >> and a parser for it
>> >>
>> >> packageP :: Parser PackageDec
>> >> packageP = do
>> >>    literal “package"
>> >>    x  <- identifier
>> >>    xs <- many ((:) <$> char '.' <*> identifier)
>> >>    return $ Pkg . concat $ (x:xs)
>> >>
>> >> so I’m parsing for this sort  of string
>> >> “package some.sort.of.name”
>> >>
>> >> and I’m trying to rewrite the packageP parser in applicative style. As
>> >> a not quite correct start I have
>> >
>> > Hello Mike,
>> >
>> >    I am not really sure what you are doing here? You are parsing a dot
>> > separated list (like.this.one) but at the end you are concatenating all
>> > together, why?
>> > Are you sure you are not wanting [String] instead of String?
>> >
>> > If so, Parsec comes with some handy parser combinators [1], maybe one of
>> > them could fit your bill:
>> >
>> >    -- should work
>> >    packageP = literal "package" *> Pkg <$> sepEndBy1 identifier (char
>> > '.')
>> >
>> > [1]
>> > https://hackage.haskell.org/package/parsec-3.1.11/docs/Text-Parsec-Combinator.html
>> > <https://hackage.haskell.org/package/parsec-3.1.11/docs/Text-Parsec-Combinator.html>
>> > _______________________________________________
>> > Beginners mailing list
>> > [hidden email] <mailto:[hidden email]>
>> > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>> > <http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners>
>> -------------- next part --------------
>> An HTML attachment was scrubbed...
>> URL:
>> <http://mail.haskell.org/pipermail/beginners/attachments/20170414/66a17133/attachment.html>
>>
>> ------------------------------
>>
>> Subject: Digest Footer
>>
>> _______________________________________________
>> Beginners mailing list
>> [hidden email]
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>>
>>
>> ------------------------------
>>
>> End of Beginners Digest, Vol 106, Issue 7
>> *****************************************
>
>
>
> _______________________________________________
> Beginners mailing list
> [hidden email]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Beginners Digest, Vol 106, Issue 7

Frank Lugala

Can   anyone  suggest a good Haskell  IDE  for  windows?




From: Beginners <[hidden email]> on behalf of David McBride <[hidden email]>
Sent: Tuesday, April 18, 2017 4:22 PM
To: The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell
Subject: Re: [Haskell-beginners] Beginners Digest, Vol 106, Issue 7
 
That depends on what package you are using to parse.  If you are using
parsec, you can use the string function from Text.Parsec.Char.  If you
are using some other package, it probably has a different name for it.

On Tue, Apr 18, 2017 at 8:39 AM, Andrey Klaus <[hidden email]> wrote:
> Hello everybody,
>
> A small question.
> -----
> packageP = do
>     literal “package"
> -----
>
> what is the "literal" in this code? My problem is
>
> $ ghc ParserTest.hs
> [1 of 1] Compiling ParserTest       ( ParserTest.hs, ParserTest.o )
>
> ParserTest.hs:11:5: Not in scope: ‘literal’
>
> $ ghc --version
> The Glorious Glasgow Haskell Compilation System, version 7.10.3
>
> Is this because I use old version of software?
>
> Thanks,
> Andrey
>
>
>
> 2017-04-14 21:58 GMT+03:00 <[hidden email]>:
>>
>> Send Beginners mailing list submissions to
>>         [hidden email]
>>
>> To subscribe or unsubscribe via the World Wide Web, visit
>>         http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


>> or, via email, send a message with subject or body 'help' to
>>         [hidden email]
>>
>> You can reach the person managing the list at
>>         [hidden email]
>>
>> When replying, please edit your Subject line so it is more specific
>> than "Re: Contents of Beginners digest..."
>>
>>
>> Today's Topics:
>>
>>    1.  Parsing (mike h)
>>    2. Re:  Parsing (David McBride)
>>    3. Re:  Parsing (Francesco Ariis)
>>    4. Re:  Parsing (mike h)
>>    5. Re:  Parsing (mike h)
>>
>>
>> ----------------------------------------------------------------------
>>
>> Message: 1
>> Date: Fri, 14 Apr 2017 19:02:37 +0100
>> From: mike h <[hidden email]>
>> To: The Haskell-Beginners Mailing List - Discussion of primarily
>>         beginner-level topics related to Haskell <[hidden email]>
>> Subject: [Haskell-beginners] Parsing
>> Message-ID: <[hidden email]>
>> Content-Type: text/plain; charset=utf-8
>>
>> I have
>> data PackageDec = Pkg String deriving Show
>>
>> and a parser for it
>>
>> packageP :: Parser PackageDec
>> packageP = do
>>     literal “package"
>>     x  <- identifier
>>     xs <- many ((:) <$> char '.' <*> identifier)
>>     return $ Pkg . concat $ (x:xs)
>>
>> so I’m parsing for this sort  of string
>> “package some.sort.of.name”
>>
>> and I’m trying to rewrite the packageP parser in applicative style. As a
>> not quite correct start I have
>>
>> packageP' :: Parser PackageDec
>> packageP' = literal "package" >>  Pkg . concat <$> many ((:) <$> char '.'
>> <*> identifier)
>>
>> but I can’t see how to get the ‘first’ identifier into this sequence -
>> i.e. the bit that corresponds to  x <- identifier        in the
>> monadic version.
>>
>> in ghci
>> λ-> :t many ((:) <$> char '.' <*> identifier)
>> many ((:) <$> char '.' <*> identifier) :: Parser [[Char]]
>>
>> so I think that somehow I need to get the ‘first’ identifier into a list
>> just after  Pkg . concat  so that the whole list gets flattened and
>> everybody is happy!
>>
>> Any help appreciated.
>>
>> Thanks
>> Mike
>>
>>
>>
>>
>>
>>
>>
>> ------------------------------
>>
>> Message: 2
>> Date: Fri, 14 Apr 2017 14:17:42 -0400
>> From: David McBride <[hidden email]>
>> To: The Haskell-Beginners Mailing List - Discussion of primarily
>>         beginner-level topics related to Haskell <[hidden email]>
>> Subject: Re: [Haskell-beginners] Parsing
>> Message-ID:
>>
>> <CAN+Tr42ifDF62sXo6WDq32rBAPHQ+[hidden email]>
>> Content-Type: text/plain; charset=UTF-8
>>
>> Try breaking it up into pieces.  There a literal "package" which is
>> dropped.  There is a first identifier, then there are the rest of the
>> identifiers (a list), then those two things are combined somehow (with
>> :).
>>
>> literal "package" *> (:) <$> identifier <*> restOfIdentifiers
>> where
>>   restOfIdentifiers :: Applicative f => f [String]
>>   restOfIdentifiers = many ((:) <$> char '.' <*> identifier
>>
>> I have not tested this code, but it should be close to what you are
>> looking for.
>>
>> On Fri, Apr 14, 2017 at 2:02 PM, mike h <[hidden email]>
>> wrote:
>> > I have
>> > data PackageDec = Pkg String deriving Show
>> >
>> > and a parser for it
>> >
>> > packageP :: Parser PackageDec
>> > packageP = do
>> >     literal “package"
>> >     x  <- identifier
>> >     xs <- many ((:) <$> char '.' <*> identifier)
>> >     return $ Pkg . concat $ (x:xs)
>> >
>> > so I’m parsing for this sort  of string
>> > “package some.sort.of.name”
>> >
>> > and I’m trying to rewrite the packageP parser in applicative style. As a
>> > not quite correct start I have
>> >
>> > packageP' :: Parser PackageDec
>> > packageP' = literal "package" >>  Pkg . concat <$> many ((:) <$> char
>> > '.' <*> identifier)
>> >
>> > but I can’t see how to get the ‘first’ identifier into this sequence -
>> > i.e. the bit that corresponds to  x <- identifier        in the
>> > monadic version.
>> >
>> > in ghci
>> > λ-> :t many ((:) <$> char '.' <*> identifier)
>> > many ((:) <$> char '.' <*> identifier) :: Parser [[Char]]
>> >
>> > so I think that somehow I need to get the ‘first’ identifier into a list
>> > just after  Pkg . concat  so that the whole list gets flattened and
>> > everybody is happy!
>> >
>> > Any help appreciated.
>> >
>> > Thanks
>> > Mike
>> >
>> >
>> >
>> >
>> >
>> > _______________________________________________
>> > Beginners mailing list
>> > [hidden email]
>> > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


>>
>>
>> ------------------------------
>>
>> Message: 3
>> Date: Fri, 14 Apr 2017 20:35:32 +0200
>> From: Francesco Ariis <[hidden email]>
>> To: [hidden email]
>> Subject: Re: [Haskell-beginners] Parsing
>> Message-ID: <[hidden email]>
>> Content-Type: text/plain; charset=utf-8
>>
>> On Fri, Apr 14, 2017 at 07:02:37PM +0100, mike h wrote:
>> > I have
>> > data PackageDec = Pkg String deriving Show
>> >
>> > and a parser for it
>> >
>> > packageP :: Parser PackageDec
>> > packageP = do
>> >     literal “package"
>> >     x  <- identifier
>> >     xs <- many ((:) <$> char '.' <*> identifier)
>> >     return $ Pkg . concat $ (x:xs)
>> >
>> > so I’m parsing for this sort  of string
>> > “package some.sort.of.name”
>> >
>> > and I’m trying to rewrite the packageP parser in applicative style. As a
>> > not quite correct start I have
>>
>> Hello Mike,
>>
>>     I am not really sure what you are doing here? You are parsing a dot
>> separated list (like.this.one) but at the end you are concatenating all
>> together, why?
>> Are you sure you are not wanting [String] instead of String?
>>
>> If so, Parsec comes with some handy parser combinators [1], maybe one of
>> them could fit your bill:
>>
>>     -- should work
>>     packageP = literal "package" *> Pkg <$> sepEndBy1 identifier (char
>> '.')
>>
>> [1]
>> https://hackage.haskell.org/package/parsec-3.1.11/docs/Text-Parsec-Combinator.html
>>
>>
>> ------------------------------
>>
>> Message: 4
>> Date: Fri, 14 Apr 2017 20:12:14 +0100
>> From: mike h <[hidden email]>
>> To: The Haskell-Beginners Mailing List - Discussion of primarily
>>         beginner-level topics related to Haskell <[hidden email]>
>> Subject: Re: [Haskell-beginners] Parsing
>> Message-ID: <[hidden email]>
>> Content-Type: text/plain; charset=utf-8
>>
>> Hi David,
>>
>> Thanks but I tried something like that before I posted. I’ll try again
>> maybe I mistyped.
>>
>> Mike
>> > On 14 Apr 2017, at 19:17, David McBride <[hidden email]> wrote:
>> >
>> > Try breaking it up into pieces.  There a literal "package" which is
>> > dropped.  There is a first identifier, then there are the rest of the
>> > identifiers (a list), then those two things are combined somehow (with
>> > :).
>> >
>> > literal "package" *> (:) <$> identifier <*> restOfIdentifiers
>> > where
>> >  restOfIdentifiers :: Applicative f => f [String]
>> >  restOfIdentifiers = many ((:) <$> char '.' <*> identifier
>> >
>> > I have not tested this code, but it should be close to what you are
>> > looking for.
>> >
>> > On Fri, Apr 14, 2017 at 2:02 PM, mike h <[hidden email]>
>> > wrote:
>> >> I have
>> >> data PackageDec = Pkg String deriving Show
>> >>
>> >> and a parser for it
>> >>
>> >> packageP :: Parser PackageDec
>> >> packageP = do
>> >>    literal “package"
>> >>    x  <- identifier
>> >>    xs <- many ((:) <$> char '.' <*> identifier)
>> >>    return $ Pkg . concat $ (x:xs)
>> >>
>> >> so I’m parsing for this sort  of string
>> >> “package some.sort.of.name”
>> >>
>> >> and I’m trying to rewrite the packageP parser in applicative style. As
>> >> a not quite correct start I have
>> >>
>> >> packageP' :: Parser PackageDec
>> >> packageP' = literal "package" >>  Pkg . concat <$> many ((:) <$> char
>> >> '.' <*> identifier)
>> >>
>> >> but I can’t see how to get the ‘first’ identifier into this sequence -
>> >> i.e. the bit that corresponds to  x <- identifier        in the
>> >> monadic version.
>> >>
>> >> in ghci
>> >> λ-> :t many ((:) <$> char '.' <*> identifier)
>> >> many ((:) <$> char '.' <*> identifier) :: Parser [[Char]]
>> >>
>> >> so I think that somehow I need to get the ‘first’ identifier into a
>> >> list just after  Pkg . concat  so that the whole list gets flattened and
>> >> everybody is happy!
>> >>
>> >> Any help appreciated.
>> >>
>> >> Thanks
>> >> Mike
>> >>
>> >>
>> >>
>> >>
>> >>
>> >> _______________________________________________
>> >> Beginners mailing list
>> >> [hidden email]
>> >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>> > _______________________________________________
>> > Beginners mailing list
>> > [hidden email]
>> > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>>
>>
>>
>> ------------------------------
>>
>> Message: 5
>> Date: Fri, 14 Apr 2017 20:19:40 +0100
>> From: mike h <[hidden email]>
>> To: The Haskell-Beginners Mailing List - Discussion of primarily
>>         beginner-level topics related to Haskell <[hidden email]>
>> Subject: Re: [Haskell-beginners] Parsing
>> Message-ID: <[hidden email]>
>> Content-Type: text/plain; charset="utf-8"
>>
>> Hi Francesco,
>> Yes, I think you are right with "Are you sure you are not wanting [String]
>> instead of String?”
>>
>> I could use Parsec but I’m building up a parser library from first
>> principles i.e.
>>
>> newtype Parser a = P (String -> [(a,String)])
>>
>> parse :: Parser a -> String -> [(a,String)]
>> parse (P p)  = p
>>
>> and so on….
>>
>> It’s just an exercise to see how far I can get. And its good fun. So maybe
>> I need add another combinator or to what I already have.
>>
>> Thanks
>>
>> Mike
>>
>>
>> > On 14 Apr 2017, at 19:35, Francesco Ariis <[hidden email]> wrote:
>> >
>> > On Fri, Apr 14, 2017 at 07:02:37PM +0100, mike h wrote:
>> >> I have
>> >> data PackageDec = Pkg String deriving Show
>> >>
>> >> and a parser for it
>> >>
>> >> packageP :: Parser PackageDec
>> >> packageP = do
>> >>    literal “package"
>> >>    x  <- identifier
>> >>    xs <- many ((:) <$> char '.' <*> identifier)
>> >>    return $ Pkg . concat $ (x:xs)
>> >>
>> >> so I’m parsing for this sort  of string
>> >> “package some.sort.of.name”
>> >>
>> >> and I’m trying to rewrite the packageP parser in applicative style. As
>> >> a not quite correct start I have
>> >
>> > Hello Mike,
>> >
>> >    I am not really sure what you are doing here? You are parsing a dot
>> > separated list (like.this.one) but at the end you are concatenating all
>> > together, why?
>> > Are you sure you are not wanting [String] instead of String?
>> >
>> > If so, Parsec comes with some handy parser combinators [1], maybe one of
>> > them could fit your bill:
>> >
>> >    -- should work
>> >    packageP = literal "package" *> Pkg <$> sepEndBy1 identifier (char
>> > '.')
>> >
>> > [1]
>> > https://hackage.haskell.org/package/parsec-3.1.11/docs/Text-Parsec-Combinator.html
>> > <https://hackage.haskell.org/package/parsec-3.1.11/docs/Text-Parsec-Combinator.html>
>> > _______________________________________________
>> > Beginners mailing list
>> > [hidden email] <[hidden email]>
>> > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>> > <http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners>
>> -------------- next part --------------
>> An HTML attachment was scrubbed...
>> URL:
>> <http://mail.haskell.org/pipermail/beginners/attachments/20170414/66a17133/attachment.html>
>>
>> ------------------------------
>>
>> Subject: Digest Footer
>>
>> _______________________________________________
>> Beginners mailing list
>> [hidden email]
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>>
>>
>> ------------------------------
>>
>> End of Beginners Digest, Vol 106, Issue 7
>> *****************************************
>
>
>
> _______________________________________________
> Beginners mailing list
> [hidden email]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners

_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Beginners Digest, Vol 106, Issue 7

mike thomas
I've had good luck recently with Atom and Visual Studio code on Windows 10 and MacOS.

I'm looking at the Haskell-ghc-mod, ide-Haskell and language-Haskell community packages right now on Atom,
and on  VS Code I've got Haskell ghc-mod, Haskell syntax highlighting and Haskell linter.

I hope this helps.

Also, do please trim stuff from previous posts not relevant to your question.  I can't do it to this reply because I'm on a phone at the moment, and deleting that much stuff is more trouble than it's worth.

Cheers

Mike


On 19 Apr 2017 10:17 am, "Frank Lugala" <[hidden email]> wrote:

Can   anyone  suggest a good Haskell  IDE  for  windows?




From: Beginners <[hidden email]> on behalf of David McBride <[hidden email]>
Sent: Tuesday, April 18, 2017 4:22 PM

To: The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell
Subject: Re: [Haskell-beginners] Beginners Digest, Vol 106, Issue 7
 
That depends on what package you are using to parse.  If you are using
parsec, you can use the string function from Text.Parsec.Char.  If you
are using some other package, it probably has a different name for it.

On Tue, Apr 18, 2017 at 8:39 AM, Andrey Klaus <[hidden email]> wrote:
> Hello everybody,
>
> A small question.
> -----
> packageP = do
>     literal “package"
> -----
>
> what is the "literal" in this code? My problem is
>
> $ ghc ParserTest.hs
> [1 of 1] Compiling ParserTest       ( ParserTest.hs, ParserTest.o )
>
> ParserTest.hs:11:5: Not in scope: ‘literal’
>
> $ ghc --version
> The Glorious Glasgow Haskell Compilation System, version 7.10.3
>
> Is this because I use old version of software?
>
> Thanks,
> Andrey
>
>
>
> 2017-04-14 21:58 GMT+03:00 <[hidden email]>:
>>
>> Send Beginners mailing list submissions to
>>         [hidden email]
>>
>> To subscribe or unsubscribe via the World Wide Web, visit
>>         http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Haskell-Beginners -- The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell About Haskell-Beginners


>> or, via email, send a message with subject or body 'help' to
>>         [hidden email]
>>
>> You can reach the person managing the list at
>>         [hidden email]
>>
>> When replying, please edit your Subject line so it is more specific
>> than "Re: Contents of Beginners digest..."
>>
>>
>> Today's Topics:
>>
>>    1.  Parsing (mike h)
>>    2. Re:  Parsing (David McBride)
>>    3. Re:  Parsing (Francesco Ariis)
>>    4. Re:  Parsing (mike h)
>>    5. Re:  Parsing (mike h)
>>
>>
>> ----------------------------------------------------------------------
>>
>> Message: 1
>> Date: Fri, 14 Apr 2017 19:02:37 +0100
>> From: mike h <[hidden email]>
>> To: The Haskell-Beginners Mailing List - Discussion of primarily
>>         beginner-level topics related to Haskell <[hidden email]>
>> Subject: [Haskell-beginners] Parsing
>> Message-ID: <[hidden email]>
>> Content-Type: text/plain; charset=utf-8
>>
>> I have
>> data PackageDec = Pkg String deriving Show
>>
>> and a parser for it
>>
>> packageP :: Parser PackageDec
>> packageP = do
>>     literal “package"
>>     x  <- identifier
>>     xs <- many ((:) <$> char '.' <*> identifier)
>>     return $ Pkg . concat $ (x:xs)
>>
>> so I’m parsing for this sort  of string
>> “package some.sort.of.name
>>
>> and I’m trying to rewrite the packageP parser in applicative style. As a
>> not quite correct start I have
>>
>> packageP' :: Parser PackageDec
>> packageP' = literal "package" >>  Pkg . concat <$> many ((:) <$> char '.'
>> <*> identifier)
>>
>> but I can’t see how to get the ‘first’ identifier into this sequence -
>> i.e. the bit that corresponds to  x <- identifier        in the
>> monadic version.
>>
>> in ghci
>> λ-> :t many ((:) <$> char '.' <*> identifier)
>> many ((:) <$> char '.' <*> identifier) :: Parser [[Char]]
>>
>> so I think that somehow I need to get the ‘first’ identifier into a list
>> just after  Pkg . concat  so that the whole list gets flattened and
>> everybody is happy!
>>
>> Any help appreciated.
>>
>> Thanks
>> Mike
>>
>>
>>
>>
>>
>>
>>
>> ------------------------------
>>
>> Message: 2
>> Date: Fri, 14 Apr 2017 14:17:42 -0400
>> From: David McBride <[hidden email]>
>> To: The Haskell-Beginners Mailing List - Discussion of primarily
>>         beginner-level topics related to Haskell <[hidden email]>
>> Subject: Re: [Haskell-beginners] Parsing
>> Message-ID:
>>
>> <[hidden email]>
>> Content-Type: text/plain; charset=UTF-8
>>
>> Try breaking it up into pieces.  There a literal "package" which is
>> dropped.  There is a first identifier, then there are the rest of the
>> identifiers (a list), then those two things are combined somehow (with
>> :).
>>
>> literal "package" *> (:) <$> identifier <*> restOfIdentifiers
>> where
>>   restOfIdentifiers :: Applicative f => f [String]
>>   restOfIdentifiers = many ((:) <$> char '.' <*> identifier
>>
>> I have not tested this code, but it should be close to what you are
>> looking for.
>>
>> On Fri, Apr 14, 2017 at 2:02 PM, mike h <[hidden email]>
>> wrote:
>> > I have
>> > data PackageDec = Pkg String deriving Show
>> >
>> > and a parser for it
>> >
>> > packageP :: Parser PackageDec
>> > packageP = do
>> >     literal “package"
>> >     x  <- identifier
>> >     xs <- many ((:) <$> char '.' <*> identifier)
>> >     return $ Pkg . concat $ (x:xs)
>> >
>> > so I’m parsing for this sort  of string
>> > “package some.sort.of.name
>> >
>> > and I’m trying to rewrite the packageP parser in applicative style. As a
>> > not quite correct start I have
>> >
>> > packageP' :: Parser PackageDec
>> > packageP' = literal "package" >>  Pkg . concat <$> many ((:) <$> char
>> > '.' <*> identifier)
>> >
>> > but I can’t see how to get the ‘first’ identifier into this sequence -
>> > i.e. the bit that corresponds to  x <- identifier        in the
>> > monadic version.
>> >
>> > in ghci
>> > λ-> :t many ((:) <$> char '.' <*> identifier)
>> > many ((:) <$> char '.' <*> identifier) :: Parser [[Char]]
>> >
>> > so I think that somehow I need to get the ‘first’ identifier into a list
>> > just after  Pkg . concat  so that the whole list gets flattened and
>> > everybody is happy!
>> >
>> > Any help appreciated.
>> >
>> > Thanks
>> > Mike
>> >
>> >
>> >
>> >
>> >
>> > _______________________________________________
>> > Beginners mailing list
>> > [hidden email]
>> > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Haskell-Beginners -- The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell About Haskell-Beginners


>>
>>
>> ------------------------------
>>
>> Message: 3
>> Date: Fri, 14 Apr 2017 20:35:32 +0200
>> From: Francesco Ariis <[hidden email]>
>> To: [hidden email]
>> Subject: Re: [Haskell-beginners] Parsing
>> Message-ID: <[hidden email]sa>
>> Content-Type: text/plain; charset=utf-8
>>
>> On Fri, Apr 14, 2017 at 07:02:37PM +0100, mike h wrote:
>> > I have
>> > data PackageDec = Pkg String deriving Show
>> >
>> > and a parser for it
>> >
>> > packageP :: Parser PackageDec
>> > packageP = do
>> >     literal “package"
>> >     x  <- identifier
>> >     xs <- many ((:) <$> char '.' <*> identifier)
>> >     return $ Pkg . concat $ (x:xs)
>> >
>> > so I’m parsing for this sort  of string
>> > “package some.sort.of.name
>> >
>> > and I’m trying to rewrite the packageP parser in applicative style. As a
>> > not quite correct start I have
>>
>> Hello Mike,
>>
>>     I am not really sure what you are doing here? You are parsing a dot
>> separated list (like.this.one) but at the end you are concatenating all
>> together, why?
>> Are you sure you are not wanting [String] instead of String?
>>
>> If so, Parsec comes with some handy parser combinators [1], maybe one of
>> them could fit your bill:
>>
>>     -- should work
>>     packageP = literal "package" *> Pkg <$> sepEndBy1 identifier (char
>> '.')
>>
>> [1]
>> https://hackage.haskell.org/package/parsec-3.1.11/docs/Text-Parsec-Combinator.html
>>
>>
>> ------------------------------
>>
>> Message: 4
>> Date: Fri, 14 Apr 2017 20:12:14 +0100
>> From: mike h <[hidden email]>
>> To: The Haskell-Beginners Mailing List - Discussion of primarily
>>         beginner-level topics related to Haskell <[hidden email]>
>> Subject: Re: [Haskell-beginners] Parsing
>> Message-ID: <[hidden email]>
>> Content-Type: text/plain; charset=utf-8
>>
>> Hi David,
>>
>> Thanks but I tried something like that before I posted. I’ll try again
>> maybe I mistyped.
>>
>> Mike
>> > On 14 Apr 2017, at 19:17, David McBride <[hidden email]> wrote:
>> >
>> > Try breaking it up into pieces.  There a literal "package" which is
>> > dropped.  There is a first identifier, then there are the rest of the
>> > identifiers (a list), then those two things are combined somehow (with
>> > :).
>> >
>> > literal "package" *> (:) <$> identifier <*> restOfIdentifiers
>> > where
>> >  restOfIdentifiers :: Applicative f => f [String]
>> >  restOfIdentifiers = many ((:) <$> char '.' <*> identifier
>> >
>> > I have not tested this code, but it should be close to what you are
>> > looking for.
>> >
>> > On Fri, Apr 14, 2017 at 2:02 PM, mike h <[hidden email]>
>> > wrote:
>> >> I have
>> >> data PackageDec = Pkg String deriving Show
>> >>
>> >> and a parser for it
>> >>
>> >> packageP :: Parser PackageDec
>> >> packageP = do
>> >>    literal “package"
>> >>    x  <- identifier
>> >>    xs <- many ((:) <$> char '.' <*> identifier)
>> >>    return $ Pkg . concat $ (x:xs)
>> >>
>> >> so I’m parsing for this sort  of string
>> >> “package some.sort.of.name
>> >>
>> >> and I’m trying to rewrite the packageP parser in applicative style. As
>> >> a not quite correct start I have
>> >>
>> >> packageP' :: Parser PackageDec
>> >> packageP' = literal "package" >>  Pkg . concat <$> many ((:) <$> char
>> >> '.' <*> identifier)
>> >>
>> >> but I can’t see how to get the ‘first’ identifier into this sequence -
>> >> i.e. the bit that corresponds to  x <- identifier        in the
>> >> monadic version.
>> >>
>> >> in ghci
>> >> λ-> :t many ((:) <$> char '.' <*> identifier)
>> >> many ((:) <$> char '.' <*> identifier) :: Parser [[Char]]
>> >>
>> >> so I think that somehow I need to get the ‘first’ identifier into a
>> >> list just after  Pkg . concat  so that the whole list gets flattened and
>> >> everybody is happy!
>> >>
>> >> Any help appreciated.
>> >>
>> >> Thanks
>> >> Mike
>> >>
>> >>
>> >>
>> >>
>> >>
>> >> _______________________________________________
>> >> Beginners mailing list
>> >> [hidden email]
>> >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>> > _______________________________________________
>> > Beginners mailing list
>> > [hidden email]
>> > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>>
>>
>>
>> ------------------------------
>>
>> Message: 5
>> Date: Fri, 14 Apr 2017 20:19:40 +0100
>> From: mike h <[hidden email]>
>> To: The Haskell-Beginners Mailing List - Discussion of primarily
>>         beginner-level topics related to Haskell <[hidden email]>
>> Subject: Re: [Haskell-beginners] Parsing
>> Message-ID: <[hidden email]>
>> Content-Type: text/plain; charset="utf-8"
>>
>> Hi Francesco,
>> Yes, I think you are right with "Are you sure you are not wanting [String]
>> instead of String?”
>>
>> I could use Parsec but I’m building up a parser library from first
>> principles i.e.
>>
>> newtype Parser a = P (String -> [(a,String)])
>>
>> parse :: Parser a -> String -> [(a,String)]
>> parse (P p)  = p
>>
>> and so on….
>>
>> It’s just an exercise to see how far I can get. And its good fun. So maybe
>> I need add another combinator or to what I already have.
>>
>> Thanks
>>
>> Mike
>>
>>
>> > On 14 Apr 2017, at 19:35, Francesco Ariis <[hidden email]> wrote:
>> >
>> > On Fri, Apr 14, 2017 at 07:02:37PM +0100, mike h wrote:
>> >> I have
>> >> data PackageDec = Pkg String deriving Show
>> >>
>> >> and a parser for it
>> >>
>> >> packageP :: Parser PackageDec
>> >> packageP = do
>> >>    literal “package"
>> >>    x  <- identifier
>> >>    xs <- many ((:) <$> char '.' <*> identifier)
>> >>    return $ Pkg . concat $ (x:xs)
>> >>
>> >> so I’m parsing for this sort  of string
>> >> “package some.sort.of.name
>> >>
>> >> and I’m trying to rewrite the packageP parser in applicative style. As
>> >> a not quite correct start I have
>> >
>> > Hello Mike,
>> >
>> >    I am not really sure what you are doing here? You are parsing a dot
>> > separated list (like.this.one) but at the end you are concatenating all
>> > together, why?
>> > Are you sure you are not wanting [String] instead of String?
>> >
>> > If so, Parsec comes with some handy parser combinators [1], maybe one of
>> > them could fit your bill:
>> >
>> >    -- should work
>> >    packageP = literal "package" *> Pkg <$> sepEndBy1 identifier (char
>> > '.')
>> >
>> > [1]
>> > https://hackage.haskell.org/package/parsec-3.1.11/docs/Text-Parsec-Combinator.html
>> > <https://hackage.haskell.org/package/parsec-3.1.11/docs/Text-Parsec-Combinator.html>
>> > _______________________________________________
>> > Beginners mailing list
>> > [hidden email] <[hidden email]>
>> > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>> > <http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners>
>> -------------- next part --------------
>> An HTML attachment was scrubbed...
>> URL:
>> <http://mail.haskell.org/pipermail/beginners/attachments/20170414/66a17133/attachment.html>
>>
>> ------------------------------
>>
>> Subject: Digest Footer
>>
>> _______________________________________________
>> Beginners mailing list
>> [hidden email]
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>>
>>
>> ------------------------------
>>
>> End of Beginners Digest, Vol 106, Issue 7
>> *****************************************
>
>
>
> _______________________________________________
> Beginners mailing list
> [hidden email]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners

_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners



_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners