"too polymorphic" type error

Shiv shiv@balrog.ece.ucsb.edu
Mon, 31 Jul 2000 11:41:52 -0700 (PDT)


Hi,

I am getting an unfamiliar type error and wondered if somebody could
tell me what I am doing wrong. I couldn't locate "monomorphic type
variables" in the index of both the language ref manual and the Clean
book.

The function binSort (which has the type error) takes a list of bins
([b]), a list of elements ([a]), and a membership function (b a ->
Bool), and returns a list of lists of elements ([[a]]), such that each
list contains elements belonging to a particular bin, and the last
list contains elements that belong to no given bin.

Here is the module:

--------------------------
module test3
import StdEnv
binSort :: (b a -> Bool) [b] [a] -> [[a]]
binSort isInBin bins elems
    = last (scan (insertInBin bins) ([[] \\ b <- bins]++[[]]) elems)
where
    insertInBin :: [b] [[a]] a -> [[a]] // Type Error here ************
    insertInBin [] [as:ass] e = [[e:as]:ass]
    insertInBin [bin:bins] [as:ass] e
    | isInBin bin e = [[e:as]:ass]
                    = [as:insertInBin bins ass e]
:: Interval :== (Real,Real)
isInInterval (a,b) x = a <= x && x <= b
bins =: [(-1.0,-0.5),(-0.5,0.0),(0.0,0.5),(0.5,1.0)]
pts =: [-1.1,-1.0 .. 1.2]
Start = binSort isInInterval bins pts
------------------------------

clm in Clean1.3.2 (Sun Solaris) reports:
Compiling test3
Type error [test3.icl,11,insertInBin]: specified type is too
polymorphic (contains monomorphic type variables)

Removing the type statement enables compilation with a warning:
Compiling test3
Warning [test3.icl,9,insertInBin]: function may fail
Generating code for test3
Assembling test3
Linking test3

Any advice will be appreciated. Thanks,

--shiv--