{-# Language TemplateHaskell, RankNTypes #-}
module Theory.Drasil.Theory (
Theory(..),
TheoryModel,
tm, tmNoRefs) where
import Control.Lens (Lens', view, makeLenses)
import Language.Drasil
import Data.Drasil.TheoryConcepts (thModel)
import Theory.Drasil.ModelKinds
class Theory t where
valid_context :: Lens' t [TheoryModel]
spaces :: Lens' t [SpaceDefn]
quantities :: Lens' t [QuantityDict]
operations :: Lens' t [ConceptChunk]
defined_quant :: Lens' t [ModelQDef]
invariants :: Lens' t [ModelExpr]
defined_fun :: Lens' t [ModelQDef]
data SpaceDefn
data TheoryModel = TM
{ TheoryModel -> ModelKind ModelExpr
_mk :: ModelKind ModelExpr
, TheoryModel -> [TheoryModel]
_vctx :: [TheoryModel]
, TheoryModel -> [SpaceDefn]
_spc :: [SpaceDefn]
, TheoryModel -> [QuantityDict]
_quan :: [QuantityDict]
, TheoryModel -> [ConceptChunk]
_ops :: [ConceptChunk]
, TheoryModel -> [ModelQDef]
_defq :: [ModelQDef]
, TheoryModel -> [ModelExpr]
_invs :: [ModelExpr]
, TheoryModel -> [ModelQDef]
_dfun :: [ModelQDef]
, TheoryModel -> [DecRef]
_rf :: [DecRef]
, TheoryModel -> ShortName
lb :: ShortName
, TheoryModel -> String
ra :: String
, TheoryModel -> [Sentence]
_notes :: [Sentence]
}
makeLenses ''TheoryModel
instance HasUID TheoryModel where uid :: Getter TheoryModel UID
uid = (ModelKind ModelExpr -> f (ModelKind ModelExpr))
-> TheoryModel -> f TheoryModel
Lens' TheoryModel (ModelKind ModelExpr)
mk ((ModelKind ModelExpr -> f (ModelKind ModelExpr))
-> TheoryModel -> f TheoryModel)
-> ((UID -> f UID)
-> ModelKind ModelExpr -> f (ModelKind ModelExpr))
-> (UID -> f UID)
-> TheoryModel
-> f TheoryModel
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (UID -> f UID) -> ModelKind ModelExpr -> f (ModelKind ModelExpr)
forall c. HasUID c => Getter c UID
Getter (ModelKind ModelExpr) UID
uid
instance NamedIdea TheoryModel where term :: Lens' TheoryModel NP
term = (ModelKind ModelExpr -> f (ModelKind ModelExpr))
-> TheoryModel -> f TheoryModel
Lens' TheoryModel (ModelKind ModelExpr)
mk ((ModelKind ModelExpr -> f (ModelKind ModelExpr))
-> TheoryModel -> f TheoryModel)
-> ((NP -> f NP) -> ModelKind ModelExpr -> f (ModelKind ModelExpr))
-> (NP -> f NP)
-> TheoryModel
-> f TheoryModel
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (NP -> f NP) -> ModelKind ModelExpr -> f (ModelKind ModelExpr)
forall c. NamedIdea c => Lens' c NP
Lens' (ModelKind ModelExpr) NP
term
instance Idea TheoryModel where getA :: TheoryModel -> Maybe String
getA = ModelKind ModelExpr -> Maybe String
forall c. Idea c => c -> Maybe String
getA (ModelKind ModelExpr -> Maybe String)
-> (TheoryModel -> ModelKind ModelExpr)
-> TheoryModel
-> Maybe String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Getting (ModelKind ModelExpr) TheoryModel (ModelKind ModelExpr)
-> TheoryModel -> ModelKind ModelExpr
forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view Getting (ModelKind ModelExpr) TheoryModel (ModelKind ModelExpr)
Lens' TheoryModel (ModelKind ModelExpr)
mk
instance Definition TheoryModel where defn :: Lens' TheoryModel Sentence
defn = (ModelKind ModelExpr -> f (ModelKind ModelExpr))
-> TheoryModel -> f TheoryModel
Lens' TheoryModel (ModelKind ModelExpr)
mk ((ModelKind ModelExpr -> f (ModelKind ModelExpr))
-> TheoryModel -> f TheoryModel)
-> ((Sentence -> f Sentence)
-> ModelKind ModelExpr -> f (ModelKind ModelExpr))
-> (Sentence -> f Sentence)
-> TheoryModel
-> f TheoryModel
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Sentence -> f Sentence)
-> ModelKind ModelExpr -> f (ModelKind ModelExpr)
forall c. Definition c => Lens' c Sentence
Lens' (ModelKind ModelExpr) Sentence
defn
instance HasDecRef TheoryModel where getDecRefs :: Lens' TheoryModel [DecRef]
getDecRefs = ([DecRef] -> f [DecRef]) -> TheoryModel -> f TheoryModel
Lens' TheoryModel [DecRef]
rf
instance ConceptDomain TheoryModel where cdom :: TheoryModel -> [UID]
cdom = ModelKind ModelExpr -> [UID]
forall c. ConceptDomain c => c -> [UID]
cdom (ModelKind ModelExpr -> [UID])
-> (TheoryModel -> ModelKind ModelExpr) -> TheoryModel -> [UID]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Getting (ModelKind ModelExpr) TheoryModel (ModelKind ModelExpr)
-> TheoryModel -> ModelKind ModelExpr
forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view Getting (ModelKind ModelExpr) TheoryModel (ModelKind ModelExpr)
Lens' TheoryModel (ModelKind ModelExpr)
mk
instance HasAdditionalNotes TheoryModel where getNotes :: Lens' TheoryModel [Sentence]
getNotes = ([Sentence] -> f [Sentence]) -> TheoryModel -> f TheoryModel
Lens' TheoryModel [Sentence]
notes
instance Theory TheoryModel where
valid_context :: Lens' TheoryModel [TheoryModel]
valid_context = ([TheoryModel] -> f [TheoryModel]) -> TheoryModel -> f TheoryModel
Lens' TheoryModel [TheoryModel]
vctx
spaces :: Lens' TheoryModel [SpaceDefn]
spaces = ([SpaceDefn] -> f [SpaceDefn]) -> TheoryModel -> f TheoryModel
Lens' TheoryModel [SpaceDefn]
spc
quantities :: Lens' TheoryModel [QuantityDict]
quantities = ([QuantityDict] -> f [QuantityDict])
-> TheoryModel -> f TheoryModel
Lens' TheoryModel [QuantityDict]
quan
operations :: Lens' TheoryModel [ConceptChunk]
operations = ([ConceptChunk] -> f [ConceptChunk])
-> TheoryModel -> f TheoryModel
Lens' TheoryModel [ConceptChunk]
ops
defined_quant :: Lens' TheoryModel [ModelQDef]
defined_quant = ([ModelQDef] -> f [ModelQDef]) -> TheoryModel -> f TheoryModel
Lens' TheoryModel [ModelQDef]
defq
invariants :: Lens' TheoryModel [ModelExpr]
invariants = ([ModelExpr] -> f [ModelExpr]) -> TheoryModel -> f TheoryModel
Lens' TheoryModel [ModelExpr]
invs
defined_fun :: Lens' TheoryModel [ModelQDef]
defined_fun = ([ModelQDef] -> f [ModelQDef]) -> TheoryModel -> f TheoryModel
Lens' TheoryModel [ModelQDef]
dfun
instance HasShortName TheoryModel where shortname :: TheoryModel -> ShortName
shortname = TheoryModel -> ShortName
lb
instance HasRefAddress TheoryModel where getRefAdd :: TheoryModel -> LblType
getRefAdd TheoryModel
l = IRefProg -> String -> LblType
RP (String -> IRefProg
prepend (String -> IRefProg) -> String -> IRefProg
forall a b. (a -> b) -> a -> b
$ TheoryModel -> String
forall c. CommonIdea c => c -> String
abrv TheoryModel
l) (TheoryModel -> String
ra TheoryModel
l)
instance CommonIdea TheoryModel where abrv :: TheoryModel -> String
abrv TheoryModel
_ = CI -> String
forall c. CommonIdea c => c -> String
abrv CI
thModel
instance Referable TheoryModel where
refAdd :: TheoryModel -> String
refAdd = TheoryModel -> String
ra
renderRef :: TheoryModel -> LblType
renderRef TheoryModel
l = IRefProg -> String -> LblType
RP (String -> IRefProg
prepend (String -> IRefProg) -> String -> IRefProg
forall a b. (a -> b) -> a -> b
$ TheoryModel -> String
forall c. CommonIdea c => c -> String
abrv TheoryModel
l) (TheoryModel -> String
forall s. Referable s => s -> String
refAdd TheoryModel
l)
tm :: (Quantity q, MayHaveUnit q, Concept c) => ModelKind ModelExpr ->
[q] -> [c] -> [ModelQDef] ->
[ModelExpr] -> [ModelQDef] -> [DecRef] ->
String -> [Sentence] -> TheoryModel
tm :: forall q c.
(Quantity q, MayHaveUnit q, Concept c) =>
ModelKind ModelExpr
-> [q]
-> [c]
-> [ModelQDef]
-> [ModelExpr]
-> [ModelQDef]
-> [DecRef]
-> String
-> [Sentence]
-> TheoryModel
tm ModelKind ModelExpr
mkind [q]
_ [c]
_ [ModelQDef]
_ [ModelExpr]
_ [ModelQDef]
_ [] String
_ = String -> [Sentence] -> TheoryModel
forall a. HasCallStack => String -> a
error (String -> [Sentence] -> TheoryModel)
-> String -> [Sentence] -> TheoryModel
forall a b. (a -> b) -> a -> b
$ String
"Source field of " String -> String -> String
forall a. [a] -> [a] -> [a]
++ ModelKind ModelExpr -> String
forall a. HasUID a => a -> String
showUID ModelKind ModelExpr
mkind String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
" is empty"
tm ModelKind ModelExpr
mkind [q]
q [c]
c [ModelQDef]
dq [ModelExpr]
inv [ModelQDef]
dfn [DecRef]
r String
lbe =
ModelKind ModelExpr
-> [TheoryModel]
-> [SpaceDefn]
-> [QuantityDict]
-> [ConceptChunk]
-> [ModelQDef]
-> [ModelExpr]
-> [ModelQDef]
-> [DecRef]
-> ShortName
-> String
-> [Sentence]
-> TheoryModel
TM ModelKind ModelExpr
mkind [] [] ((q -> QuantityDict) -> [q] -> [QuantityDict]
forall a b. (a -> b) -> [a] -> [b]
map q -> QuantityDict
forall q. (Quantity q, MayHaveUnit q) => q -> QuantityDict
qw [q]
q) ((c -> ConceptChunk) -> [c] -> [ConceptChunk]
forall a b. (a -> b) -> [a] -> [b]
map c -> ConceptChunk
forall c. Concept c => c -> ConceptChunk
cw [c]
c) [ModelQDef]
dq [ModelExpr]
inv [ModelQDef]
dfn [DecRef]
r (Sentence -> ShortName
shortname' (Sentence -> ShortName) -> Sentence -> ShortName
forall a b. (a -> b) -> a -> b
$ String -> Sentence
S String
lbe)
(CI -> String -> String
forall c. CommonIdea c => c -> String -> String
prependAbrv CI
thModel String
lbe)
tmNoRefs :: (Quantity q, MayHaveUnit q, Concept c) => ModelKind ModelExpr ->
[q] -> [c] -> [ModelQDef] -> [ModelExpr] -> [ModelQDef] ->
String -> [Sentence] -> TheoryModel
tmNoRefs :: forall q c.
(Quantity q, MayHaveUnit q, Concept c) =>
ModelKind ModelExpr
-> [q]
-> [c]
-> [ModelQDef]
-> [ModelExpr]
-> [ModelQDef]
-> String
-> [Sentence]
-> TheoryModel
tmNoRefs ModelKind ModelExpr
mkind [q]
q [c]
c [ModelQDef]
dq [ModelExpr]
inv [ModelQDef]
dfn String
lbe =
ModelKind ModelExpr
-> [TheoryModel]
-> [SpaceDefn]
-> [QuantityDict]
-> [ConceptChunk]
-> [ModelQDef]
-> [ModelExpr]
-> [ModelQDef]
-> [DecRef]
-> ShortName
-> String
-> [Sentence]
-> TheoryModel
TM ModelKind ModelExpr
mkind [] [] ((q -> QuantityDict) -> [q] -> [QuantityDict]
forall a b. (a -> b) -> [a] -> [b]
map q -> QuantityDict
forall q. (Quantity q, MayHaveUnit q) => q -> QuantityDict
qw [q]
q) ((c -> ConceptChunk) -> [c] -> [ConceptChunk]
forall a b. (a -> b) -> [a] -> [b]
map c -> ConceptChunk
forall c. Concept c => c -> ConceptChunk
cw [c]
c) [ModelQDef]
dq [ModelExpr]
inv [ModelQDef]
dfn [] (Sentence -> ShortName
shortname' (Sentence -> ShortName) -> Sentence -> ShortName
forall a b. (a -> b) -> a -> b
$ String -> Sentence
S String
lbe)
(CI -> String -> String
forall c. CommonIdea c => c -> String -> String
prependAbrv CI
thModel String
lbe)