The problem here is how you're calling complR
. Your definition may not be what you want either. Examine the type of complR
carefully:
complR :: Ord a => Set a -> Rel a -> Rel a
Let's substitute in the definition of Rel a = Set (a, a)
:
complR :: Ord a => Set a -> Set (a, a) -> Set (a, a)
Now, look at how you're calling it:
complR (Set [(4, 5), (3, 3)]) (Set [(1, 3)])
You're saying that the first argument has type Num b => Set (b, b)
, which means that a ~ Num b =>(b, b)
, which means that the second argument must have the type Num b => Set ((b, b), (b, b))
. Since you've typed in Set [(1, 3)]
for this argument, it attempts to unify the types Num b => b
and Num b => (b, b)
, which results in the error you see above.
How do you fix this? Your options are to either change the definition of complR
such that it has the type
complR :: Ord a => Rel a -> Rel a -> Rel a
Or fix how you're calling it as
complR (Set [3, 4, 5]) (Set [(1, 3)])
I'm not going to tell you which is correct in this situation, you'll have to determine that yourself.
A methodology to solve this sort of error is to add some explicit type annotations into your code:
complR (Set [(5, 4), (3, 3)] :: Set (Int, Int)) (Set [(1, 3)] :: Rel Int)
would have thrown the error (in GHC)
Couldn't match type `Int' with `(Int, Int)'
Expected type: Rel (Int, Int)
Actual type: Rel Int
In the second argument of `complR', namely
`(Set [(1, 3)] :: Rel Int)'
In the expression:
complR
(Set [(5, 4), (3, 3)] :: Set (Int, Int)) (Set [(1, 3)] :: Rel Int)
In an equation for `it':
it
= complR
(Set [(5, 4), (3, 3)] :: Set (Int, Int)) (Set [(1, 3)] :: Rel Int)
Which says more explicitly "Couldn't match type Int
with (Int, Int)
", which is a more clear indication of what the problem was, you're trying to use a tuple where you need a single number. It even says "Expected type: Rel (Int, Int) ... In the second argument of complR
", which tells you something is up.
As a side note, I would highly recommend dropping Hugs in favor of GHC. You'll get much more informative error messages, and a lot more features. Hugs hasn't had development since 2006, while GHC is still actively developed and has new releases regularly. Hugs also has some bugs that tend to crop up from time to time, since it hasn't had any maintenance in 8 years, so you'll be a lot better off grabbing the Haskell Platform, which includes GHC and many popular libraries.