Parsec 3.0 problems

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

Parsec 3.0 problems

Ian Duncan
Hello everyone,
I have the simple applicative parser combinator:

parseLabel = Label <$> (between spaces (char ':') (many1 alphaNum))

This gives me the error:

No instance for (Stream s m Char)
      arising from a use of `spaces' at tree.hs:18:32-37
    Possible fix: add an instance declaration for (Stream s m Char)
    In the first argument of `between', namely `spaces'
    In the second argument of `(<$>)', namely
        `(between spaces (char ':') (many1 alphaNum))'
    In the expression:
          Label <$> (between spaces (char ':') (many1 alphaNum))

When I test this function in ghci, I have no problems, yet whenever I try to
open it in a file it fails. What am I doing wrong?
For those who are curious, Label is a data constructor in the following data
type:

data Loc = Label String
 | Addr Int
deriving Show

Thanks!
Ian Duncan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/beginners/attachments/20090420/a63cee98/attachment-0001.htm
Reply | Threaded
Open this post in threaded view
|

Parsec 3.0 problems

Philippa Cowderoy
On Mon, 2009-04-20 at 18:26 -0500, Ian Duncan wrote:

> No instance for (Stream s m Char)
>       arising from a use of `spaces' at tree.hs:18:32-37
>     Possible fix: add an instance declaration for (Stream s m Char)
>     In the first argument of `between', namely `spaces'
>     In the second argument of `(<$>)', namely
>         `(between spaces (char ':') (many1 alphaNum))'
>     In the expression:
>           Label <$> (between spaces (char ':') (many1 alphaNum))
>
>
> When I test this function in ghci, I have no problems, yet whenever I
> try to open it in a file it fails. What am I doing wrong?

Looks like you're getting bitten by the monomorphism restriction. {-#
LANGUAGE NoMonomorphismRestriction #-} at the top of the source file to
make it go away.

The MR is a real usability problem for Parsec 3, sadly :-( You may find
it easier to work with the latest version of Parsec 2, which is still
the recommended version for most purposes.

--
Philippa Cowderoy <[hidden email]>