Purpose and semantics of classes of type Eq1 / Ord1

Given the following type, how should I implement an instance Eq1?

data Foo a = Bar String | Baz a [a]

instance Eq1 Foo where
    liftEq _ (Bar a) (Bar b) = a == b -- can't use f
    liftEq f (Baz a aa) (Baz b bb) = f a b && liftEq f aa bb -- instance for lists
    liftEq _ _ _ = False

Is the above example true? Should I use it manually in GHC 8.0.2? There is a library deriving-compatthat uses TH, but why is it called -compat?

+4
source share
1 answer

The point Eq1and friends provide restrictions intended for use with type constructors that accept type constructors - for example, monad transformers or Fix(cf. How to get instances in recursion schemes ) - in a more neat way that does not require extensions such as FlexibleContextsor UndecidableInstances.

?

, .

GHC 8.0.2?

Eq1 GHC-. .

deriving-compat, TH, -compat?

, "compat" , , GHC GHC.

+2

Source: https://habr.com/ru/post/1670792/


All Articles