[clean-list] What am I missing ?
Pieter Koopman
pieter@cs.kun.nl
Thu, 05 Jul 2001 17:09:41 +0200
Hello Sebastien,
At 15:16 05-07-2001 +0200, sebastien FURIC wrote:
> When I compile the following program, I get a type error:
>
>Type error: [test.icl,10,partition_]: specified type is too polymorphic
>(contains monomorphic type variables)
>
> If I delete the line where the type of partition_ is declared I have no
>error. Why is the declared type wrong ?
>
>partition :: (!a -> Bool) ![a] -> ([a], [a])
>partition f l = partition_ l [] []
>where
> partition_ :: ![a] [a] [a] -> ([a], [a])
> partition_ [] accepted rejected = (accepted, rejected)
> partition_ [x : xs] accepted rejected
> | f x = partition_ xs [x : accepted] rejected
> | otherwise = partition_ xs accepted [x : rejected]
This is a known problem. The type variable, a, in partition and partition_
should be equal since the predicate, f, is applied to elements of the
argument list. Currently this cannot be specified. We are working on a
solution.
For the moment you should omit the type of the local function, or pass the
predicate, f, explicitly as argument to the local function partition_ (the
rule lifter will add it if you don't).
The last solution yields the definition
partition :: (!a -> Bool) ![a] -> ([a], [a])
partition f l = partition_ f l [] []
where
partition_ :: (!a -> Bool) ![a] [a] [a] -> ([a], [a])
partition_ f [] accepted rejected = (accepted, rejected)
partition_ f [x : xs] accepted rejected
| f x = partition_ f xs [x : accepted] rejected
| otherwise = partition_ f xs accepted [x : rejected]
Have fun, Pieter Koopman