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