Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Haskell Question

Name: Anonymous 2007-09-05 21:29 ID:Ci6wlsOk

I'm trying to make a program in Haskell that compares two [Char] and returns a [Integer] of all the positions that the Chars are the same.

commons :: [Char] -> [Char] -> [Integer]
commons a b = case (a, b) of
        ([], _) -> []
        (_, []) -> []
        (_, _) -> fcommons 0 a b []

fcommons n s1 s2 set = case (s1, s2) of
        ([], _) -> set
        (_, []) -> set
        (a:b, c:d) -> if a==c then fcommons n+1 b d (set:n)
        else fcommons n+1 b d set

I end up getting this error:

ERROR "commons.hs":7 - Type error in function binding
*** Term           : fcommons
*** Type           : [a] -> [b] -> [b] -> a -> a
*** Does not match : [a] -> a
*** Because        : unification would give infinite type

I'm new to Haskell and have no idea why this is happening.

Name: Anonymous 2011-03-22 18:26

>>18
you win hard
/thread

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List