{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE PostfixOperators #-}
{-# LANGUAGE Rank2Types #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TupleSections #-}
module Theory.Drasil.ConstraintSet (
ConstraintSet,
mkConstraintSet,
) where
import Control.Lens (makeLenses, (^.))
import qualified Data.List.NonEmpty as NE
import Language.Drasil
data ConstraintSet e = CL {
forall e. ConstraintSet e -> ConceptChunk
_con :: ConceptChunk,
forall e. ConstraintSet e -> NonEmpty e
_invs :: NE.NonEmpty e
}
makeLenses ''ConstraintSet
instance HasUID (ConstraintSet e) where uid :: Lens' (ConstraintSet e) UID
uid = forall e. Lens' (ConstraintSet e) ConceptChunk
con forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall c. HasUID c => Lens' c UID
uid
instance NamedIdea (ConstraintSet e) where term :: Lens' (ConstraintSet e) NP
term = forall e. Lens' (ConstraintSet e) ConceptChunk
con forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall c. NamedIdea c => Lens' c NP
term
instance Idea (ConstraintSet e) where getA :: ConstraintSet e -> Maybe String
getA = forall c. Idea c => c -> Maybe String
getA forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall s a. s -> Getting a s a -> a
^. forall e. Lens' (ConstraintSet e) ConceptChunk
con)
instance Definition (ConstraintSet e) where defn :: Lens' (ConstraintSet e) Sentence
defn = forall e. Lens' (ConstraintSet e) ConceptChunk
con forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall c. Definition c => Lens' c Sentence
defn
instance ConceptDomain (ConstraintSet e) where cdom :: ConstraintSet e -> [UID]
cdom = forall c. ConceptDomain c => c -> [UID]
cdom forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall s a. s -> Getting a s a -> a
^. forall e. Lens' (ConstraintSet e) ConceptChunk
con)
instance Express e => Express (ConstraintSet e) where
express :: ConstraintSet e -> ModelExpr
express = forall (t :: * -> *) a. Foldable t => (a -> a -> a) -> t a -> a
foldr1 forall r. ExprC r => r -> r -> r
($&&) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a -> b) -> [a] -> [b]
map forall c. Express c => c -> ModelExpr
express forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. NonEmpty a -> [a]
NE.toList forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall s a. s -> Getting a s a -> a
^. forall e e.
Lens (ConstraintSet e) (ConstraintSet e) (NonEmpty e) (NonEmpty e)
invs)
instance RequiresChecking (ConstraintSet Expr) Expr Space where
requiredChecks :: ConstraintSet Expr -> [(Expr, Space)]
requiredChecks ConstraintSet Expr
cs = forall a b. (a -> b) -> [a] -> [b]
map (,Space
Boolean) forall a b. (a -> b) -> a -> b
$ forall a. NonEmpty a -> [a]
NE.toList (ConstraintSet Expr
cs forall s a. s -> Getting a s a -> a
^. forall e e.
Lens (ConstraintSet e) (ConstraintSet e) (NonEmpty e) (NonEmpty e)
invs)
mkConstraintSet :: ConceptChunk -> NE.NonEmpty e -> ConstraintSet e
mkConstraintSet :: forall e. ConceptChunk -> NonEmpty e -> ConstraintSet e
mkConstraintSet = forall e. ConceptChunk -> NonEmpty e -> ConstraintSet e
CL