<div dir="ltr">For anyone else benefit, this is how I fixed issue.<div><br></div><div>1. download Parsing.lhs from author's website.</div><div>2. Also download parser.lhs and paste contents into my prog_haskell.hs file, removing text comments and > symbols.</div>
<div>3. At top of my prog_haskell.hs file you need import Parsing</div><div><br></div><div>You can then call the functions in WinGHCi, eg eval "3+5*2"</div><div><br></div><div>For some reason I was not able to work out how to import both Parsing.lhs and parser.lhs together.  Will have to read up on modules later.</div>
<div><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On 7 January 2014 11:43, Christian Maeder <span dir="ltr"><<a href="mailto:Christian.Maeder@dfki.de" target="_blank">Christian.Maeder@dfki.de</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Angus,<br>
<br>
did you get an answer for your question? (Just pressing "reply" only answers to the list, as happened to my earlier answer to your initial question.)<br>
<br>
I don't know if WinGHCi works like ghci under linux (and I don't know which files Parsing.lhs and parser.lhs you tried to load.)<br>
<br>
At the ghci Prompt you can type ":browse" to see which names are in scope. Maybe parser.lhs could not be loaded for some reason that I cannot reproduce. (Maybe eval is explicitly not exported?)<br>
<br>
Cheers Christian<br>
<br>
<br>
Am 03.01.2014 18:43, schrieb Angus Comber:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">
I found some notes on the authors website explaining that the book code<br>
would no longer work.  So I downloaded two files: Parsing.lhs and<br>
parser.lhs.  In WinGHCi I then issued :load on both files.<br>
<br>
parser.lhs contains a function, eval, as follows:<br>
<br>
<other stuff above><br>
 > eval                          :: String -> Int<br>
 > eval xs                       =  case (parse expr xs) of<br>
 >                                     [(n,[])]  -> n<br>
 >                                     [(_,out)] -> error ("unused input<br>
" ++ out)<br>
 >                                     []        -> error "invalid input"<br>
<br>
But in WinGHCi if I run: eval "2*3+4" I get error := Not in scope: `eval'<br>
<br>
I assume this is some sort of namespaces feature of Haskell that I have<br>
not read about?  Or I somehow have to state what library modules to<br>
use???  Can anyone help?<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
On 3 January 2014 15:58, Angus Comber <<a href="mailto:anguscomber@gmail.com" target="_blank">anguscomber@gmail.com</a><br></div><div><div class="h5">
<mailto:<a href="mailto:anguscomber@gmail.com" target="_blank">anguscomber@gmail.com</a>><u></u>> wrote:<br>
<br>
    I am reading Chapter 8 of Programming Haskell by Graham Hutton and<br>
    trying to run the code in the book.<br>
<br>
    It seems that there are already defined library implementations of<br>
    Parser so I used Parser' and generally ' on the end of each<br>
    identifier to attempt to eliminate this problem.<br>
<br>
    So the code I copied from the book is:<br>
<br>
    type Parser' a = String -> [(a, String)]<br>
<br>
    return' :: a -> Parser' a<br>
    return' v = \x -> [(v, x)]<br>
<br>
    failure' :: Parser' a<br>
    failure' = \inp -> []<br>
<br>
    -- item doesn't seem to conflict with anything so no '<br>
    item :: Parser' Char<br>
    item = \inp -> case inp of<br>
                         [] -> []<br>
                         (x:xs) -> [(x,xs)]<br>
<br>
<br>
    parse' :: Parser' a -> String -> [(a, String)]<br>
    parse' p inp = p inp<br>
<br>
<br>
    p :: Parser' (Char, Char)<br>
    p = do  x <- item<br>
             item<br>
             y <- item<br>
             return' (x,y)<br>
<br>
    When run from WinGHCi I get error:<br>
<br>
    prog_haskell.hs:458:9:<br>
        Couldn't match type `[(Char, String)]' with `Char'<br>
         Expected type: String -> [((Char, Char), String)]<br>
           Actual type: Parser' ([(Char, String)], [(Char, String)])<br>
         In the return type of a call of return'<br>
         In a stmt of a 'do' block: return' (x, y)<br>
         In the expression:<br>
           do { x <- item;<br>
                item;<br>
                y <- item;<br>
                return' (x, y) }<br>
<br>
    458.9 is line at end with return' (x,y)<br>
<br>
<br>
    Also in the chapter was the definition of >>= sequencing.  as in:<br>
<br>
    (>>=) :: Parser a -> (a -> Parser b) -> Parser b<br>
    p >>= f  =  \inp -> case parse p inp of<br>
                           [] -> []<br>
                           [(v,out)] -> parse (f v) out<br>
<br>
    But I assumed this would already be in standard Haskell library and<br>
    so I didn't need to define.  But even when I did add, still get same<br>
    error.<br>
<br>
    How do I fix this?<br>
<br>
<br>
<br>
<br></div></div><div class="im">
______________________________<u></u>_________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org" target="_blank">Beginners@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/beginners" target="_blank">http://www.haskell.org/<u></u>mailman/listinfo/beginners</a><br>
<br>
</div></blockquote>
<br>
</blockquote></div><br></div>