What is wrong with my Clean program which compiler give the error "cannot unify demanded type with offered type"

33 Views Asked by At

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

1

There are 1 best solutions below

1
On BEST ANSWER
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.