Unable to fetch instance (haskell error)

My assignment defines the following:

type Rel a = Set (a,a)

complR :: Ord a => Set a -> Rel a -> Rel a
complR (Set xs) r = Set [(x,y) | x <- xs, y <- xs, not (inR r (x,y))]

The dial type can be called, for example, as follows: (Set [(1,2)]). When I try to call such a function, I get the error message "I can not output the instance." I am quite sure that this is because of my call and because of Rel a in the specific. InR is also defined in the assignment, which I did not include here.

What am I doing wrong? I call it this way:

complR (Set [(5,4), (3,3)]) (Set [(1,3)])

Thank!

Edit: I don't think the assignment uses Data.Set. I do not see it. I see Data.List. However, I see that there is the following: newtype Set a = Set [a] output (Eq, Ord). Type for inR: Ord a => Rel a → (a, a) → Bool. The files used for this purpose are http://www.cwi.nl/~jve/rcrh/REL.hs and http://www.cwi.nl/~jve/rcrh/SetOrd.hs .

The compR function is placed in the REL.hs. file The error that occurs when calling compR:

ERROR - Cannot infer instance
*** Instance   : Num (b,a)
*** Expression : complR (Set [(5,4),(3,3)]) (Set [(1,3)])
+4
source share
2 answers

The problem is how you call complR. Perhaps your definition is not what you want. Carefully study the type complR:

complR :: Ord a => Set a -> Rel a -> Rel a

Substitute in the definition Rel a = Set (a, a):

complR :: Ord a => Set a -> Set (a, a) -> Set (a, a)

, :

complR (Set [(4, 5), (3, 3)]) (Set [(1, 3)])

, Num b => Set (b, b), , a ~ Num b =>(b, b), , Num b => Set ((b, b), (b, b)). Set [(1, 3)] , Num b => b Num b => (b, b), , .

? complR ,

complR :: Ord a => Rel a -> Rel a -> Rel a

,

complR (Set [3, 4, 5]) (Set [(1, 3)])

, , .


, :

complR (Set [(5, 4), (3, 3)] :: Set (Int, Int)) (Set [(1, 3)] :: Rel Int)

( 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)

" Int (Int, Int)", , , , . " : Rel (Int, Int)... complR", , - .


, Hugs GHC. . Hugs 2006 , GHC - . Hugs , , 8 , Haskell Platform, GHC .

+4

type Rel a = Set (a,a), complR -

complR :: Ord a => Set a -> Rel a -> Rel a

a, a s, .

complR (Set [(5,4), (3,3)]) (Set [(4,5)])

, , , (!) , - Num, , .

+2

Source: https://habr.com/ru/post/1546622/


All Articles