我想弄清楚類型類和GADTS之間的差異,特別是在使用-XMultiParamTypeClasses擴展名時。 似乎都具有類似用途: class MyClass a b where
f :: a -> b -> Bool
instance MyClass String String where
f s1 s2 = ...
instance MyClass Int Int
我有代碼看起來像這樣: /**
* A divisor that operates on real numbers.
*/
case class RealDivisor(divisor: Long)
extends Divisor[Double, Double]
with Divisor[Long, Double] // ... with Divisor[
我無法理解類型類別函數的Coq計算(或缺少它)的行爲。下面是一個最小的工作示例: Class class1 : Set := { class_func1 : nat -> nat }.
Class class2 : Set := { class_func2 : nat -> nat
; class_prop2 : forall x : nat, x = x
寫這樣的實例聲明工作正常: data Either a b = Left a | Right b
instance Functor (Either a) where
fmap _ (Left x) = Left x
fmap f (Right x) = Right (f x)
現在可以說,我想這個反轉,左應用於F到值: instance Functor (Either
什麼我目前要做的是創建一個名爲Value類型: data Value = Num Int
| Sum Int Int
| Dif Int Int
| Neg Int
deriving (Eq)
與我要實現一個eval函數: eval :: Value -> Int
eval (Num x) = x
eval (Sum x y) =
我有一個基本的類型類: class MyClass a where
(-+) :: a -> a -> a
instance MyClass Int where
e1 -+ e2 = e1 + e2 * 100
myFunction :: MyClass a => a -> a -> a
myFunction e1 e2 = e1 -+ e2
我明白上面是如何工作