1 {-# LANGUAGE DataKinds #-}
2 {-# LANGUAGE DefaultSignatures #-}
3 {-# LANGUAGE FlexibleContexts #-}
4 {-# LANGUAGE FlexibleInstances #-}
5 {-# LANGUAGE MultiParamTypeClasses #-}
6 {-# LANGUAGE OverloadedStrings #-}
7 {-# LANGUAGE Rank2Types #-}
8 {-# LANGUAGE ScopedTypeVariables #-}
9 {-# LANGUAGE TypeFamilies #-}
10 {-# LANGUAGE TypeOperators #-}
11 {-# LANGUAGE UndecidableInstances #-}
12 {-# OPTIONS_GHC -fno-warn-orphans #-}
13 -- | Symantic for 'Eq'.
14 module Language.Symantic.Compiling.Eq where
17 import qualified Data.Eq as Eq
18 import Data.Proxy (Proxy(..))
19 import Data.String (IsString)
20 import Data.Text (Text)
21 import Prelude hiding ((==), (/=))
23 import Language.Symantic.Typing
24 import Language.Symantic.Compiling.Term
25 import Language.Symantic.Compiling.Bool
26 import Language.Symantic.Interpreting
27 import Language.Symantic.Transforming.Trans
30 class Sym_Eq term where
31 (==) :: Eq a => term a -> term a -> term Bool
32 (/=) :: Eq a => term a -> term a -> term Bool
34 default (==) :: (Trans t term, Eq a) => t term a -> t term a -> t term Bool
35 default (/=) :: (Trans t term, Eq a) => t term a -> t term a -> t term Bool
37 (==) = trans_map2 (==)
38 (/=) = trans_map2 (/=)
43 type instance Sym_of_Iface (Proxy Eq) = Sym_Eq
44 type instance Consts_of_Iface (Proxy Eq) = Proxy Eq ': Consts_imported_by Eq
45 type instance Consts_imported_by Eq = '[]
47 instance Sym_Eq HostI where
50 instance Sym_Eq TextI where
51 (==) = textI_infix "==" (Precedence 4)
52 (/=) = textI_infix "/=" (Precedence 4)
53 instance (Sym_Eq r1, Sym_Eq r2) => Sym_Eq (DupI r1 r2) where
54 (==) = dupI2 sym_Eq (==)
55 (/=) = dupI2 sym_Eq (/=)
57 instance Const_from Text cs => Const_from Text (Proxy Eq ': cs) where
58 const_from "Eq" k = k (ConstZ kind)
59 const_from s k = const_from s $ k . ConstS
60 instance Show_Const cs => Show_Const (Proxy Eq ': cs) where
61 show_const ConstZ{} = "Eq"
62 show_const (ConstS c) = show_const c
65 Proj_ConC cs (Proxy Eq)
66 instance -- Term_fromI
68 , Lexem ast ~ LamVarName
69 , Inj_Const (Consts_of_Ifaces is) Bool
70 , Inj_Const (Consts_of_Ifaces is) (->)
71 , Inj_Const (Consts_of_Ifaces is) Eq
72 , Proj_Con (Consts_of_Ifaces is)
74 ) => Term_fromI is (Proxy Eq) ast where
75 term_fromI ast ctx k =
79 _ -> Left $ Error_Term_unsupported
81 op2_from (op::forall term a. (Sym_Eq term, Eq a) => term a -> term a -> term Bool) =
82 from_ast1 ast $ \ast_x as ->
83 term_from ast_x ctx $ \ty_x (TermLC x) ->
84 check_constraint (At (Just ast_x) (tyEq :$ ty_x)) $ \Con ->
85 k as (ty_x ~> tyBool) $ TermLC $
89 tyEq :: Inj_Const cs Eq => Type cs Eq
90 tyEq = TyConst inj_const
92 sym_Eq :: Proxy Sym_Eq
95 syEq :: IsString a => [Syntax a] -> Syntax a