I have declared the following type
type Parser a = String -> [(a,String)]
and some function to operate on the parser as the bellow
succeed :: a -> Parser a
succeed v = \inp -> [(v,inp)]
when trying to run stack ghci
in order to test the above function succeed
I got an error that Parser is not an instance of show
so I've tried to update the code and add the following
instance Show Parser where
show [(v,inp)] = show (v,inp)
but I got an error that Show
is expecting the argument to be *
but it is * -> *
How could I solve that so I can test my function in GHCi
?
Alright, the short answer is: you cannot do this.
The long answer involves using a newtype
:
newtype Parser a = Parser [(a, String)]
instance Show (Parser a) where
...
For an explanation, see this question.