1 {-# LANGUAGE UndecidableInstances #-}
2 {-# OPTIONS_GHC -fno-warn-orphans #-}
3 -- | Symantic for 'Integer'.
4 module Language.Symantic.Lib.Integer where
6 import qualified Data.Text as Text
8 import Language.Symantic
9 import Language.Symantic.Grammar
11 -- * Class 'Sym_Integer'
12 type instance Sym (Proxy Integer) = Sym_Integer
13 class Sym_Integer term where
14 integer :: Integer -> term Integer
15 default integer :: Sym_Integer (UnT term) => Trans term => Integer -> term Integer
16 integer = trans . integer
19 instance Sym_Integer Eval where
21 instance Sym_Integer View where
22 integer a = View $ \_p _v ->
24 instance (Sym_Integer r1, Sym_Integer r2) => Sym_Integer (Dup r1 r2) where
25 integer x = integer x `Dup` integer x
28 instance (Sym_Integer term, Sym_Lambda term) => Sym_Integer (BetaT term)
31 instance ClassInstancesFor Integer where
32 proveConstraintFor _ (TyApp _ (TyConst _ _ q) z)
33 | Just HRefl <- proj_ConstKiTy @_ @Integer z
35 _ | Just Refl <- proj_Const @Enum q -> Just Dict
36 | Just Refl <- proj_Const @Eq q -> Just Dict
37 | Just Refl <- proj_Const @Integral q -> Just Dict
38 | Just Refl <- proj_Const @Num q -> Just Dict
39 | Just Refl <- proj_Const @Ord q -> Just Dict
40 | Just Refl <- proj_Const @Real q -> Just Dict
41 | Just Refl <- proj_Const @Show q -> Just Dict
43 proveConstraintFor _c _q = Nothing
44 instance TypeInstancesFor Integer
54 ) => Gram_Term_AtomsFor src ss g Integer where
58 (\i src -> BinTree0 $ Token_Term $ TermVT_CF $ (`setSource` src) $ teInteger $ read i)
59 <$> some (choice $ char <$> ['0'..'9'])
61 instance ModuleFor src ss Integer
64 tyInteger :: Source src => Inj_Len vs => Type src vs Integer
65 tyInteger = tyConst @(K Integer) @Integer
67 teInteger :: Source src => Inj_Sym ss Integer => Integer -> Term src ss ts '[] Integer
68 teInteger i = Term noConstraint tyInteger $ teSym @Integer $ integer i