Hi All,
Sorry if this is a very lame question but i am a beginner and much appreciate if some one could correct me?
I am reading haskell book and curious why the return type of the bind operator look odd to me
For the given definitions
type Parser a = String -> [(a, String)]
item :: Parser Char
item = \inp -> case inp of
[] -> []
(x:xs) -> [(x,xs)]
bind :: Parser a -> (a -> Parser b) -> Parser b
p `bind` f = \inp -> concat [ f x inp' | (x, inp') <- p inp]
when I define z in GHCI as
let z = item `bind` (\x -> (\y -> result (x,y))) "Rohit"
the return type is
>> :t z
z :: Parser ([Char], Char)
Question:
(1) Shouldn't the return type of (Char, [Char])? looking at the list comprehension, "(x, inp') <- p inp" should yield -> "('r', "ohit")". Next f x inp' is left associative, so f x should yield character 'r' and pass to the lambda that should return result tuple ('r', "ohit"), but why is it that z type is ([Char], char) :: (x,y)
(2) How can i print the value of z in the above case on the ghci
Many thanks,
Rohit