<div dir="ltr">I found some notes on the authors website explaining that the book code would no longer work.  So I downloaded two files: Parsing.lhs and parser.lhs.  In WinGHCi I then issued :load on both files.<div><br></div>
<div>parser.lhs contains a function, eval, as follows:</div><div><br></div><div><other stuff above></div><div><div>> eval                          :: String -> Int</div><div>> eval xs                       =  case (parse expr xs) of</div>
<div>>                                     [(n,[])]  -> n</div><div>>                                     [(_,out)] -> error ("unused input " ++ out)</div><div>>                                     []        -> error "invalid input"</div>
</div><div><br></div><div>But in WinGHCi if I run: eval "2*3+4" I get error := Not in scope: `eval'</div><div><br></div><div>I assume this is some sort of namespaces feature of Haskell that I have not read about?  Or I somehow have to state what library modules to use???  Can anyone help?</div>
<div><br></div><div><br></div><div><br><div><br></div><div><br></div></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On 3 January 2014 15:58, Angus Comber <span dir="ltr"><<a href="mailto:anguscomber@gmail.com" target="_blank">anguscomber@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>I am reading Chapter 8 of Programming Haskell by Graham Hutton and trying to run the code in the book.</div>
<div><br></div><div>It seems that there are already defined library implementations of Parser so I used Parser' and generally ' on the end of each identifier to attempt to eliminate this problem.</div>
<div><br></div><div>So the code I copied from the book is:</div><div><br></div><div>type Parser' a = String -> [(a, String)]</div><div><br></div><div>return' :: a -> Parser' a</div><div>return' v = \x -> [(v, x)]</div>

<div><br></div><div>failure' :: Parser' a</div><div>failure' = \inp -> []</div><div><br></div><div>-- item doesn't seem to conflict with anything so no '</div><div>item :: Parser' Char</div><div>

item = \inp -> case inp of</div><div>                    [] -> []</div><div>                    (x:xs) -> [(x,xs)]</div><div><br></div><div><br></div><div>parse' :: Parser' a -> String -> [(a, String)]</div>

<div>parse' p inp = p inp</div><div><br></div><div><br></div><div>p :: Parser' (Char, Char)</div><div>p = do  x <- item</div><div>        item</div><div>        y <- item</div><div>        return' (x,y)</div>

<div><br></div><div>When run from WinGHCi I get error:</div><div><br></div><div>prog_haskell.hs:458:9:</div><div>   Couldn't match type `[(Char, String)]' with `Char'</div><div>    Expected type: String -> [((Char, Char), String)]</div>

<div>      Actual type: Parser' ([(Char, String)], [(Char, String)])</div><div>    In the return type of a call of return'</div><div>    In a stmt of a 'do' block: return' (x, y)</div><div>    In the expression:</div>

<div>      do { x <- item;</div><div>           item;</div><div>           y <- item;</div><div>           return' (x, y) }</div><div><br></div><div>458.9 is line at end with return' (x,y)</div><div><br></div>

<div><br></div><div>Also in the chapter was the definition of >>= sequencing.  as in:</div><div><br></div><div>(>>=) :: Parser a -> (a -> Parser b) -> Parser b</div><div>p >>= f  =  \inp -> case parse p inp of</div>

<div>                      [] -> []</div><div>                      [(v,out)] -> parse (f v) out</div><div><br></div><div>But I assumed this would already be in standard Haskell library and so I didn't need to define.  But even when I did add, still get same error.</div>

<div><br></div><div>How do I fix this?   </div><div><br></div></div>
</blockquote></div><br></div>