I'm trying to write my PDF parser and I got stick for this type checking failure and it bothered me for days.
Here's my app.icl
module app
import StdEnv
Start = "Hello, world!"
:: ParseResult a
= ParseOk a [Char]
| ParseFail [Char]
match :: [Char] Real -> ([Char] -> (ParseResult Real))
match x y = matchYes x y
matchYes :: [Char] Real [Char] -> ParseResult Real
matchYes [] t _ = ParseOk t
matchYes [_:_] _ [] = ParseFail []
matchYes [x:xs] t [y:ys] = if (x == y) (matchYes xs t ys) (ParseFail [])
the output is
Type error [app.icl,14,matchYes]: near (case ... ) : cannot unify demanded type with offered type:
[Char] -> ParseResult Real
ParseResult Real
I run nitrile build
and it fails. I really don't get it.
As far as I know, matchYes
always fit the type [Char] Real [Char] -> ParseResult Real
ParseOk a [Char]
ParseOk
takes two arguments: one of type a
(Real
in this case) and one of type [Char]
.
matchYes [] t _ = ParseOk t
Here you're partially applying ParseOk
to a single argument of type Real
. So what you're left with is a function of type [Char] -> ParseResult Real
when the expected type would have been just ParseResult Real
.