]> Git — Sourcephile - haskell/symantic.git/blob - Language/Symantic/Expr/Eq.hs
init
[haskell/symantic.git] / Language / Symantic / Expr / Eq.hs
1 {-# LANGUAGE DefaultSignatures #-}
2 {-# LANGUAGE FlexibleContexts #-}
3 {-# LANGUAGE PolyKinds #-}
4 {-# LANGUAGE ScopedTypeVariables #-}
5 {-# LANGUAGE TypeFamilies #-}
6 {-# LANGUAGE TypeOperators #-}
7 {-# LANGUAGE NoMonomorphismRestriction #-}
8 -- | Expression for 'Eq'.
9 module Language.Symantic.Expr.Eq where
10
11 import Data.Proxy (Proxy(..))
12 import Data.Type.Equality ((:~:)(Refl))
13 import Prelude hiding ((==))
14
15 import Language.Symantic.Trans.Common
16 import Language.Symantic.Type
17 import Language.Symantic.Expr.Common
18
19 -- * Class 'Sym_Eq'
20 -- | Symantic.
21 class Sym_Eq repr where
22 (==) :: Eq a => repr a -> repr a -> repr Bool
23 default (==) :: (Trans t repr, Eq a)
24 => t repr a -> t repr a -> t repr Bool
25 (==) = trans_map2 (==)
26 infix 4 ==
27
28 -- * Type 'Expr_Eq'
29 -- | Expression.
30 data Expr_Eq (root:: *)
31 type instance Root_of_Expr (Expr_Eq root) = root
32 type instance Type_of_Expr (Expr_Eq root) = No_Type
33 type instance Sym_of_Expr (Expr_Eq root) repr = (Sym_Eq repr)
34 type instance Error_of_Expr ast (Expr_Eq root) = No_Error_Expr
35
36 eq_from
37 :: forall root ty ast hs ret.
38 ( ty ~ Type_Root_of_Expr (Expr_Eq root)
39 , Lift_Type_Root Type_Bool (Type_Root_of_Expr root)
40 , Eq_Type (Type_Root_of_Expr root)
41 , Expr_from ast root
42 , Lift_Error_Expr (Error_Expr (Error_of_Type ast ty) ty ast)
43 (Error_of_Expr ast root)
44 , Root_of_Expr root ~ root
45 , Constraint_Type Eq ty
46 ) => ast -> ast
47 -> Expr_From ast (Expr_Eq root) hs ret
48 eq_from ast_x ast_y ex ast ctx k =
49 expr_from (Proxy::Proxy root) ast_x ctx $
50 \(ty_x::Type_Root_of_Expr root h_x) (Forall_Repr_with_Context x) ->
51 expr_from (Proxy::Proxy root) ast_y ctx $
52 \(ty_y::Type_Root_of_Expr root h_y) (Forall_Repr_with_Context y) ->
53 check_eq_type ex ast ty_x ty_y $ \Refl ->
54 check_constraint_type ex (Proxy::Proxy Eq) ast ty_x $ \Dict ->
55 k type_bool $ Forall_Repr_with_Context $
56 \c -> x c == y c