2016-03-24 24 views
0

LevelEq ve Ord'un bir örneğini yapmak mümkün mü?Haskell: İki tipin bir örneği nasıl yapılır?

instance Eq Ord Level where 
    compare First Second = LT 
    ... 

Bu

instance (Ord, Eq) => Level where ... 

denedim Ama benim data Level üzerinde deriving (Eq) kullanabilirsiniz biliyorum bir hata

‘compare’ is not a (visible) method of class ‘Level’ 

var. Ama ben data'u değiştiremiyorum.

cevap

7

Kullanım iki durum

instance Eq Level where 
    x == y = ... 
instance Ord Level where 
    compare x y = ... 

Alternatif standalone deriving extension kullanın:

{-# LANGUAGE StandaloneDeriving #-} 
...  -- ^^^^^^^^^^^^^^^^^^ must be at the top of the file 
deriving instance (Eq Level) 
deriving instance (Ord Level) 
+0

yeap işe yarıyor. – barbara

+0

@chi, ah, bunu kaçırdı. Afedersiniz. – dfeuer

İlgili konular