type Parser a = String -> [(a, String)]Hi,I am learning haskell and wondering why my definition of firstAndThird does not work with the do operator, however when i try to use the same using bind (firstandThird2) it works as expected. I basically want to return a tuple of first and third character of a string. Can someone please correct me what i might be overseeing?I have pasted the same code on codetidy in case if the email lose formatting.Many Thanks,Rohitzero :: Parser azero = \inp -> []result :: a -> Parser aresult x = \inp -> [(x, inp)]item :: Parser Charitem = \inp -> case inp of[] -> [](x:xs) -> [(x,xs)]bind :: Parser a -> (a -> Parser b) -> Parser bp `bind` f = \inp -> concat [ ((f x) inp') | (x, inp') <- p inp]sat :: (Char -> Bool) -> Parser Charsat predicate = item `bind` (\x -> if predicate x then result x else zero )lower :: Parser Charlower = sat (\x -> 'a' <= x && x <= 'z')firstAndThird :: Parser (Char, Char)firstAndThird = do x <- itemitemy <- itemreturn (x,y)firstAndThird2 :: Parser (Char, Char)firstAndThird2 = item `bind` \x ->item `bind` \y ->item `bind` \z ->result (x,z)
_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://www.haskell.org/mailman/listinfo/beginners