I'm trying to figure out the differences between class types and GADTS, especially when using the extension -XMultiParamTypeClasses.
Both have similar features:
class MyClass a b where
f :: a -> b -> Bool
instance MyClass String String where
f s1 s2 = ...
instance MyClass Int Int where
f i1 i2 = ...
data Gadt a where
F :: String -> String -> Bool
F2 :: Int -> Int -> Bool
So far, the only difference that I really see is that GADT allows an interface like functions to have flexible number arguments:
data Gadt a where
PassTwoArgs :: String -> String -> Gadt Bool
PassOneArgs :: String -> Gadt Bool
myFunction :: Gadt a -> a
myFunction (PassTwoArgs s1 s2) = ...
myFunction (PassOneArgs s1) = ...
This is not easy to do with type classes so far.
Are there any other differences or uses of one another?
source
share