1 {-# LANGUAGE InstanceSigs #-}
2 {-# LANGUAGE UndecidableInstances #-}
3 {-# OPTIONS_GHC -fno-warn-orphans #-}
4 -- | Symantic for 'Posting'.
5 module Hcompta.LCC.Sym.Posting where
7 import Control.Monad (liftM)
9 import Data.Either (Either)
10 import Data.Function (($))
11 import Data.Maybe (Maybe(..))
12 import Data.Monoid (Monoid(..))
14 import Data.Type.Equality ((:~:)(Refl))
15 import Text.Show (Show(..))
16 import qualified Prelude ()
18 import Hcompta.LCC.Account
19 import Hcompta.LCC.Amount
20 import Hcompta.LCC.Posting (Posting)
21 import qualified Hcompta.LCC.Posting as LCC
22 import Language.Symantic
23 import qualified Language.Symantic.Lib as Sym
24 import Language.Symantic.Lib ((~>))
26 -- * Class 'Sym_Posting'
27 class Sym_Posting term where
28 posting_account :: term Posting -> term Account
29 posting_amounts :: term Posting -> term Amounts
30 default posting_account :: Trans t term => t term Posting -> t term Account
31 default posting_amounts :: Trans t term => t term Posting -> t term Amounts
32 posting_account = trans_map1 posting_account
33 posting_amounts = trans_map1 posting_amounts
35 type instance Sym_of_Iface (Proxy Posting) = Sym_Posting
36 type instance TyConsts_of_Iface (Proxy Posting) = Proxy Posting ': TyConsts_imported_by (Proxy Posting)
37 type instance TyConsts_imported_by (Proxy Posting) =
42 instance Sym_Posting HostI where
43 posting_account = liftM LCC.posting_account
44 posting_amounts = liftM LCC.posting_amounts
45 instance Sym_Posting TextI where
46 posting_account = textI1 "posting_account"
47 posting_amounts = textI1 "posting_amounts"
48 instance (Sym_Posting r1, Sym_Posting r2) => Sym_Posting (DupI r1 r2) where
49 posting_account = dupI1 @Sym_Posting posting_account
50 posting_amounts = dupI1 @Sym_Posting posting_amounts
53 ( Read_TyNameR TyName cs rs
54 , Inj_TyConst cs Posting
55 ) => Read_TyNameR TyName cs (Proxy Posting ': rs) where
56 read_TyNameR _cs (TyName "Posting") k = k (ty @Posting)
57 read_TyNameR _rs raw k = read_TyNameR (Proxy @rs) raw k
58 instance Show_TyConst cs => Show_TyConst (Proxy Posting ': cs) where
59 show_TyConst TyConstZ{} = "Posting"
60 show_TyConst (TyConstS c) = show_TyConst c
62 instance Proj_TyFamC cs Sym.TyFam_MonoElement Posting
64 instance -- Proj_TyConC
65 ( Proj_TyConst cs Posting
66 , Proj_TyConsts cs (TyConsts_imported_by (Proxy Posting))
67 ) => Proj_TyConC cs (Proxy Posting) where
68 proj_TyConC _ (TyConst q :$ TyConst c)
69 | Just Refl <- eq_skind (kind_of_TyConst c) SKiType
70 , Just Refl <- proj_TyConst c (Proxy @Posting)
72 _ | Just Refl <- proj_TyConst q (Proxy @Eq) -> Just TyCon
73 | Just Refl <- proj_TyConst q (Proxy @Show) -> Just TyCon
75 proj_TyConC _c _q = Nothing
76 data instance TokenT meta (ts::[*]) (Proxy Posting)
77 = Token_Term_Posting_account
78 | Token_Term_Posting_amounts
79 deriving instance (Eq meta, Eq_Token meta ts) => Eq (TokenT meta ts (Proxy Posting))
80 deriving instance (Show meta, Show_Token meta ts) => Show (TokenT meta ts (Proxy Posting))
83 ( Inj_TyConst cs Posting
85 , Inj_TyConst cs Account
86 , Inj_TyConst cs Amounts
89 ) => CompileI cs is (Proxy Posting) where
91 :: forall meta ctx ret ls rs.
92 TokenT meta is (Proxy Posting)
93 -> CompileT meta ctx ret cs is ls (Proxy Posting ': rs)
96 Token_Term_Posting_account -> get (ty @Account) posting_account
97 Token_Term_Posting_amounts -> get (ty @Amounts) posting_amounts
100 :: forall a. Type cs a
101 -> (forall term. Sym_Posting term => term Posting -> term a)
102 -> Either (Error_Term meta cs is) ret
104 k (ty @Posting ~> ty_a) $ TermO $
106 instance -- TokenizeT
107 Inj_Token meta ts Posting =>
108 TokenizeT meta ts (Proxy Posting) where
109 tokenizeT _t = mempty
110 { tokenizers_infix = tokenizeTMod []
111 [ tokenize0 "posting_account" infixN5 Token_Term_Posting_account
112 , tokenize0 "posting_amounts" infixN5 Token_Term_Posting_amounts
115 instance -- Gram_Term_AtomsT
120 , Inj_Token meta ts Posting
121 ) => Gram_Term_AtomsT meta ts (Proxy Posting) g where