<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>