I'm trying to figure out the differences between type classes and GADTS, especially when using -XMultiParamTypeClasses
extension.
Both appear to have similar uses:
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 I really see is that GADT's enable a function type interface to have a 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) = ...
Whilst this isn't easily done with type classes.
Are there any other differences or use cases to use one over the other?