list comprehension

Ch. A. Herrmann
Fri, 19 Oct 2001 11:28:33 +0200

>>>>> "Stephanie" == Stephanie Randles <> writes:

    Stephanie> Hi, I have a script here

    Stephanie> interleave :: [Integer] -> [Strings] -> [String]
    Stephanie> interleave (x:xs) (y:ys) = words [a | a <- (unwords
    Stephanie> [(show x), (filter (/= 1) y), "+"])]

    Stephanie> and the error message i receive is

    Stephanie> (Instance of Num Char required for definition of
    Stephanie> interleave)

the difficult error message is due to the flexibility of the
type class system in Haskell.

The variable y is of type String, i.e., a list of Char. You try
to compare a number (/= 1) with a character (an element of y taken
by filter).
The number constant 1 imposes the type class Num (for numbers) via the
comparison to this character, but you have not made Char an
instance of class Num (define  +, -, * on Char). Probably that's
not what you want; the error message does not address the logical
source of error but the point where the constraints mismatched.

Good luck
Christoph Herrmann