1 {-# LANGUAGE UndecidableInstances #-}
2 {-# OPTIONS_GHC -fno-warn-orphans #-}
3 {-# OPTIONS_GHC -fconstraint-solver-iterations=5 #-}
4 -- | Symantic for '()'.
5 module Language.Symantic.Lib.Unit where
7 import qualified Data.Function as Fun
10 import Data.Type.Equality ((:~:)(Refl))
11 import Prelude hiding ((&&), not, (||))
13 import Language.Symantic.Parsing
14 import Language.Symantic.Typing
15 import Language.Symantic.Compiling
16 import Language.Symantic.Interpreting
17 import Language.Symantic.Transforming
20 class Sym_Unit term where
22 default unit :: Trans t term => t term ()
23 unit = trans_lift unit
25 type instance Sym_of_Iface (Proxy ()) = Sym_Unit
26 type instance TyConsts_of_Iface (Proxy ()) = Proxy () ': TyConsts_imported_by ()
27 type instance TyConsts_imported_by () =
36 instance Sym_Unit HostI where
38 instance Sym_Unit TextI where
39 unit = TextI $ \_p _v -> "()"
40 instance (Sym_Unit r1, Sym_Unit r2) => Sym_Unit (DupI r1 r2) where
41 unit = unit `DupI` unit
44 ( Read_TyNameR TyName cs rs
46 ) => Read_TyNameR TyName cs (Proxy () ': rs) where
47 read_TyNameR _cs (TyName "()") k = k (ty @())
48 read_TyNameR _rs raw k = read_TyNameR (Proxy @rs) raw k
49 instance Show_TyConst cs => Show_TyConst (Proxy () ': cs) where
50 show_TyConst TyConstZ{} = "()"
51 show_TyConst (TyConstS c) = show_TyConst c
53 instance -- Proj_TyConC
55 , Proj_TyConsts cs (TyConsts_imported_by ())
56 ) => Proj_TyConC cs (Proxy ()) where
57 proj_TyConC _ (TyConst q :$ TyConst c)
58 | Just Refl <- eq_skind (kind_of_TyConst c) SKiType
59 , Just Refl <- proj_TyConst c (Proxy @())
61 _ | Just Refl <- proj_TyConst q (Proxy @Bounded) -> Just TyCon
62 | Just Refl <- proj_TyConst q (Proxy @Enum) -> Just TyCon
63 | Just Refl <- proj_TyConst q (Proxy @Eq) -> Just TyCon
64 | Just Refl <- proj_TyConst q (Proxy @Monoid) -> Just TyCon
65 | Just Refl <- proj_TyConst q (Proxy @Ord) -> Just TyCon
66 | Just Refl <- proj_TyConst q (Proxy @Show) -> Just TyCon
68 proj_TyConC _c _q = Nothing
69 data instance TokenT meta (ts::[*]) (Proxy ())
71 deriving instance Eq_Token meta ts => Eq (TokenT meta ts (Proxy ()))
72 deriving instance Show_Token meta ts => Show (TokenT meta ts (Proxy ()))
75 ) => CompileI cs is (Proxy ()) where
78 Token_Term_Unit -> k (ty @()) $ TermO $ Fun.const unit
80 -- Inj_Token meta ts () =>
81 TokenizeT meta ts (Proxy ())
82 instance -- Gram_Term_AtomsT
86 , Inj_Token meta ts ()
87 ) => Gram_Term_AtomsT meta ts (Proxy ()) g where
91 (\meta -> ProTok $ inj_EToken meta $ Token_Term_Unit)