I'm writing a parser
And it's working as it is :
type Parser a = String -> Maybe (a ,String)
parseInt :: Parser Int
parseInt "" = Nothing
parseInt s = case reads s ::[(Int, String)] of
[(x, s)]-> Just(x, s)
_ -> Nothing
parseChar :: Char -> Parser Char
parseChar a str | a == head str = Just (a, tail str)
| otherwise = Nothing
But i need too change
type Parser a = String -> Maybe (a ,String)
to
data Parser a = Parser { runParser :: String -> Maybe (a , String ) }
As soon as I do, it every function i wrote do not compile anymore, what are the step to do this change, and, what is happening ?
data Parser a = MkParser { runParser :: String -> Maybe (a , String ) }instead. it will be much less confusing. you can always remove theMks if you have to, afterwards.runParser. read more about it by searching for "Haskell record syntax".