{-# LANGUAGE GADTs #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeOperators #-}
module Data.Comp.Ordering
(
OrdF(..)
) where
import Data.Comp.Derive
import Data.Comp.Derive.Utils
import Data.Comp.Equality ()
import Data.Comp.Ops
import Data.Comp.Term
instance (OrdF f, Ord a) => Ord (Cxt h f a) where
compare :: Cxt h f a -> Cxt h f a -> Ordering
compare = Cxt h f a -> Cxt h f a -> Ordering
forall (f :: * -> *) a. (OrdF f, Ord a) => f a -> f a -> Ordering
compareF
instance OrdF f => OrdF (Cxt h f) where
compareF :: Cxt h f a -> Cxt h f a -> Ordering
compareF (Term f (Cxt h f a)
e1) (Term f (Cxt h f a)
e2) = f (Cxt h f a) -> f (Cxt h f a) -> Ordering
forall (f :: * -> *) a. (OrdF f, Ord a) => f a -> f a -> Ordering
compareF f (Cxt h f a)
e1 f (Cxt h f a)
e2
compareF (Hole a
h1) (Hole a
h2) = a -> a -> Ordering
forall a. Ord a => a -> a -> Ordering
compare a
h1 a
h2
compareF Term{} Hole{} = Ordering
LT
compareF Hole{} Term{} = Ordering
GT
instance (OrdF f, OrdF g) => OrdF (f :+: g) where
compareF :: (:+:) f g a -> (:+:) f g a -> Ordering
compareF (Inl f a
_) (Inr g a
_) = Ordering
LT
compareF (Inr g a
_) (Inl f a
_) = Ordering
GT
compareF (Inl f a
x) (Inl f a
y) = f a -> f a -> Ordering
forall (f :: * -> *) a. (OrdF f, Ord a) => f a -> f a -> Ordering
compareF f a
x f a
y
compareF (Inr g a
x) (Inr g a
y) = g a -> g a -> Ordering
forall (f :: * -> *) a. (OrdF f, Ord a) => f a -> f a -> Ordering
compareF g a
x g a
y
$(derive [makeOrdF] $ [''Maybe, ''[]] ++ tupleTypes 2 10)