]> 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.Repr.Dup
16 import Language.Symantic.Trans.Common
17 import Language.Symantic.Type
18 import Language.Symantic.Expr.Common
19
20 -- * Class 'Sym_Eq'
21 -- | Symantic.
22 class Sym_Eq repr where
23 (==) :: Eq a => repr a -> repr a -> repr Bool
24 default (==) :: (Trans t repr, Eq a)
25 => t repr a -> t repr a -> t repr Bool
26 (==) = trans_map2 (==)
27 infix 4 ==
28
29 instance (Sym_Eq r1, Sym_Eq r2) => Sym_Eq (Dup r1 r2) where
30 (==) (x1 `Dup` x2) (y1 `Dup` y2) = (==) x1 y1 `Dup` (==) x2 y2
31
32 -- * Type 'Expr_Eq'
33 -- | Expression.
34 data Expr_Eq (root:: *)
35 type instance Root_of_Expr (Expr_Eq root) = root
36 type instance Type_of_Expr (Expr_Eq root) = No_Type
37 type instance Sym_of_Expr (Expr_Eq root) repr = (Sym_Eq repr)
38 type instance Error_of_Expr ast (Expr_Eq root) = No_Error_Expr
39
40 eq_from
41 :: forall root ty ast hs ret.
42 ( ty ~ Type_Root_of_Expr (Expr_Eq root)
43 , Type_Root_Lift Type_Bool (Type_Root_of_Expr root)
44 , Type_Eq (Type_Root_of_Expr root)
45 , Expr_from ast root
46 , Error_Expr_Lift (Error_Expr (Error_of_Type ast ty) ty ast)
47 (Error_of_Expr ast root)
48 , Root_of_Expr root ~ root
49 , Type_Constraint Eq ty
50 ) => ast -> ast
51 -> Expr_From ast (Expr_Eq root) hs ret
52 eq_from ast_x ast_y ex ast ctx k =
53 expr_from (Proxy::Proxy root) ast_x ctx $
54 \(ty_x::Type_Root_of_Expr root h_x) (Forall_Repr_with_Context x) ->
55 expr_from (Proxy::Proxy root) ast_y ctx $
56 \(ty_y::Type_Root_of_Expr root h_y) (Forall_Repr_with_Context y) ->
57 check_type_eq ex ast ty_x ty_y $ \Refl ->
58 check_type_constraint ex (Proxy::Proxy Eq) ast ty_x $ \Dict ->
59 k type_bool $ Forall_Repr_with_Context $
60 \c -> x c == y c