{-# LANGUAGE DefaultSignatures #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE PolyKinds #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE TypeOperators #-} {-# LANGUAGE NoMonomorphismRestriction #-} -- | Expression for 'Eq'. module Language.Symantic.Expr.Eq where import Data.Proxy (Proxy(..)) import Data.Type.Equality ((:~:)(Refl)) import Prelude hiding ((==)) import Language.Symantic.Repr.Dup import Language.Symantic.Trans.Common import Language.Symantic.Type import Language.Symantic.Expr.Common -- * Class 'Sym_Eq' -- | Symantic. class Sym_Eq repr where (==) :: Eq a => repr a -> repr a -> repr Bool default (==) :: (Trans t repr, Eq a) => t repr a -> t repr a -> t repr Bool (==) = trans_map2 (==) infix 4 == instance (Sym_Eq r1, Sym_Eq r2) => Sym_Eq (Dup r1 r2) where (==) (x1 `Dup` x2) (y1 `Dup` y2) = (==) x1 y1 `Dup` (==) x2 y2 -- * Type 'Expr_Eq' -- | Expression. data Expr_Eq (root:: *) type instance Root_of_Expr (Expr_Eq root) = root type instance Type_of_Expr (Expr_Eq root) = No_Type type instance Sym_of_Expr (Expr_Eq root) repr = (Sym_Eq repr) type instance Error_of_Expr ast (Expr_Eq root) = No_Error_Expr eq_from :: forall root ty ast hs ret. ( ty ~ Type_Root_of_Expr (Expr_Eq root) , Type_Root_Lift Type_Bool (Type_Root_of_Expr root) , Eq_Type (Type_Root_of_Expr root) , Expr_from ast root , Error_Expr_Lift (Error_Expr (Error_of_Type ast ty) ty ast) (Error_of_Expr ast root) , Root_of_Expr root ~ root , Constraint_Type Eq ty ) => ast -> ast -> Expr_From ast (Expr_Eq root) hs ret eq_from ast_x ast_y ex ast ctx k = expr_from (Proxy::Proxy root) ast_x ctx $ \(ty_x::Type_Root_of_Expr root h_x) (Forall_Repr_with_Context x) -> expr_from (Proxy::Proxy root) ast_y ctx $ \(ty_y::Type_Root_of_Expr root h_y) (Forall_Repr_with_Context y) -> check_eq_type ex ast ty_x ty_y $ \Refl -> check_constraint_type ex (Proxy::Proxy Eq) ast ty_x $ \Dict -> k type_bool $ Forall_Repr_with_Context $ \c -> x c == y c