{-# LANGUAGE DefaultSignatures #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE TypeOperators #-} -- | Expression for 'Ord'. module Language.Symantic.Expr.Ord where import Data.Proxy (Proxy(..)) import Data.Type.Equality ((:~:)(Refl)) import Prelude hiding (compare) import Language.Symantic.Trans.Common import Language.Symantic.Type import Language.Symantic.Expr.Root import Language.Symantic.Expr.Error import Language.Symantic.Expr.From import Language.Symantic.Expr.Eq -- * Class 'Sym_Ord' -- | Symantic. class Sym_Eq repr => Sym_Ord repr where compare :: Ord a => repr a -> repr a -> repr Ordering default compare :: (Trans t repr, Ord a) => t repr a -> t repr a -> t repr Ordering compare = trans_map2 compare -- * Type 'Expr_Ord' -- | Expression. data Expr_Ord (root:: *) type instance Root_of_Expr (Expr_Ord root) = root type instance Type_of_Expr (Expr_Ord root) = Type_Ordering type instance Sym_of_Expr (Expr_Ord root) repr = (Sym_Ord repr) type instance Error_of_Expr ast (Expr_Ord root) = No_Error_Expr instance Constraint_Type Ord (Type_Var0 root) instance Constraint_Type Ord (Type_Var1 root) compare_from :: forall root ty ast hs ret. ( ty ~ Type_Root_of_Expr (Expr_Ord root) , Eq_Type ty , Expr_from ast root , Lift_Type Type_Ordering (Type_of_Expr root) , Lift_Error_Expr (Error_Expr (Error_of_Type ast ty) ty ast) (Error_of_Expr ast root) , Root_of_Expr root ~ root , Constraint_Type Ord ty ) => ast -> ast -> Expr_From ast (Expr_Ord root) hs ret compare_from ast_x ast_y ex ast ctx k = expr_from (Proxy::Proxy root) ast_x ctx $ \(ty_x::ty h_x) (Forall_Repr_with_Context x) -> expr_from (Proxy::Proxy root) ast_y ctx $ \(ty_y::ty h_y) (Forall_Repr_with_Context y) -> check_eq_type ex ast ty_x ty_y $ \Refl -> check_constraint_type ex (Proxy::Proxy Ord) ast ty_x $ \Dict -> k type_ordering $ Forall_Repr_with_Context $ \c -> x c `compare` y c