[Haskell-cafe] Closed classes

Imants Cekusins imantc at gmail.com
Thu Feb 18 09:38:24 UTC 2016


.. and one more option:

-- Enum order specifies the order instances are tried
data InstanceChoice = ChooseFirst | ChooseSecond | IgnoreBoth deriving Enum


type family Choose a b where
  Choose Int y = ChooseFirst
  Choose x Int = ChooseSecond
  Choose x y = IgnoreBoth


class (Choose a b) => Closed a b where
  fun :: a -> b -> Int


instance Closed Int y where fun x _ = x
instance Closed x Int where fun _ y = y
instance Closed x y where fun _ _ = 0


More information about the Haskell-Cafe mailing list