Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions code/drasil-lang/lib/Drasil/Code/CodeExpr/Class.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Drasil.Code.CodeExpr.Class where

import Control.Lens ((^.))

import Drasil.Database (HasUID(..))
import Drasil.Database (HasUID(uid), IsChunk)

import Drasil.Code.Classes (IsArgumentName, Callable)
import Drasil.Code.CodeExpr.Lang (CodeExpr(FCall, New, Message, Field))
Expand All @@ -13,26 +13,26 @@ import Language.Drasil.Expr.Class (ExprC(..))

class CodeExprC r where
-- | Constructs a CodeExpr for actor creation (constructor call)
new :: (Callable f, HasUID f, CodeIdea f) => f -> [r] -> r
new :: (Callable f, IsChunk f, CodeIdea f) => f -> [r] -> r

-- | Constructs a CodeExpr for actor creation (constructor call) that uses named arguments
newWithNamedArgs :: (Callable f, HasUID f, CodeIdea f, HasUID a,
newWithNamedArgs :: (Callable f, IsChunk f, CodeIdea f, IsChunk a,
IsArgumentName a) => f -> [r] -> [(a, r)] -> r

-- | Constructs a CodeExpr for actor messaging (method call)
msg :: (Callable f, HasUID f, CodeIdea f, HasUID c, HasSpace c, CodeIdea c)
msg :: (Callable f, IsChunk f, CodeIdea f, IsChunk c, HasSpace c, CodeIdea c)
=> c -> f -> [r] -> r

-- | Constructs a CodeExpr for actor messaging (method call) that uses named arguments
msgWithNamedArgs :: (Callable f, HasUID f, CodeIdea f, HasUID c, HasSpace c,
CodeIdea c, HasUID a, IsArgumentName a) => c -> f -> [r] -> [(a, r)] ->
msgWithNamedArgs :: (Callable f, IsChunk f, CodeIdea f, IsChunk c, HasSpace c,
CodeIdea c, IsChunk a, IsArgumentName a) => c -> f -> [r] -> [(a, r)] ->
r

-- | Constructs a CodeExpr representing the field of an actor
field :: CodeVarChunk -> CodeVarChunk -> r

-- | Similar to 'apply', but takes a relation to apply to 'FCall'.
applyWithNamedArgs :: (HasUID f, HasSymbol f, HasUID a, IsArgumentName a) => f
applyWithNamedArgs :: (IsChunk f, HasSymbol f, IsChunk a, IsArgumentName a) => f
-> [r] -> [(a, r)] -> r

instance CodeExprC CodeExpr where
Expand Down
8 changes: 7 additions & 1 deletion code/drasil-lang/lib/Drasil/Code/CodeVar.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Drasil.Code.CodeVar where

import Control.Lens ((^.), view, makeLenses, Lens')

import Drasil.Database (HasUID(uid), (+++))
import Drasil.Database (HasUID(uid), HasChunkRefs(..), (+++))

import Drasil.Code.Classes (Callable)
import Drasil.Code.CodeExpr.Lang (CodeExpr)
Expand Down Expand Up @@ -43,6 +43,8 @@ makeLenses ''CodeChunk

-- | Finds the 'UID' of the 'DefinedQuantityDict' used to make the 'CodeChunk'.
instance HasUID CodeChunk where uid = qc . uid
instance HasChunkRefs CodeChunk where
chunkRefs = const mempty -- FIXME: `chunkRefs` should actually collect the referenced chunks.
-- | Finds the term ('NP') of the 'DefinedQuantityDict' used to make the 'CodeChunk'.
instance NamedIdea CodeChunk where term = qc . term
-- | Finds the idea contained in the 'DefinedQuantityDict' used to make the 'CodeChunk'.
Expand Down Expand Up @@ -70,6 +72,8 @@ makeLenses ''CodeVarChunk

-- | Finds the 'UID' of the 'CodeChunk' used to make the 'CodeVarChunk'.
instance HasUID CodeVarChunk where uid = ccv . uid
instance HasChunkRefs CodeVarChunk where
chunkRefs = const mempty -- FIXME: `chunkRefs` should actually collect the referenced chunks.
-- | Finds the term ('NP') of the 'CodeChunk' used to make the 'CodeVarChunk'.
instance NamedIdea CodeVarChunk where term = ccv . term
-- | Finds the idea contained in the 'CodeChunk' used to make the 'CodeVarChunk'.
Expand All @@ -95,6 +99,8 @@ makeLenses ''CodeFuncChunk

-- | Finds the 'UID' of the 'CodeChunk' used to make the 'CodeFuncChunk'.
instance HasUID CodeFuncChunk where uid = ccf . uid
instance HasChunkRefs CodeFuncChunk where
chunkRefs = const mempty -- FIXME: `chunkRefs` should actually collect the referenced chunks.
-- | Finds the term ('NP') of the 'CodeChunk' used to make the 'CodeFuncChunk'.
instance NamedIdea CodeFuncChunk where term = ccf . term
-- | Finds the idea contained in the 'CodeChunk' used to make the 'CodeFuncChunk'.
Expand Down
4 changes: 3 additions & 1 deletion code/drasil-lang/lib/Language/Drasil/Chunk/CommonIdea.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module Language.Drasil.Chunk.CommonIdea (

import Control.Lens (makeLenses, (^.), view)

import Drasil.Database (UID, HasUID(uid))
import Drasil.Database (UID, HasUID(uid), HasChunkRefs(..))
import Utils.Drasil (repUnd)

import Language.Drasil.Chunk.NamedIdea (IdeaDict, nc)
Expand All @@ -32,6 +32,8 @@ makeLenses ''CI

-- | Finds 'UID' of the 'IdeaDict' used to make the 'CI'.
instance HasUID CI where uid = nc' . uid
instance HasChunkRefs CI where
chunkRefs = const mempty -- FIXME: `chunkRefs` should actually collect the referenced chunks.
-- | Finds term ('NP') of the 'IdeaDict' used to make the 'CI'.
instance NamedIdea CI where term = nc' . term
-- | Finds the idea of a 'CI' (abbreviation).
Expand Down
4 changes: 3 additions & 1 deletion code/drasil-lang/lib/Language/Drasil/Chunk/Constrained.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module Language.Drasil.Chunk.Constrained (

import Control.Lens ((^.), makeLenses, view)

import Drasil.Database (HasUID(..))
import Drasil.Database (HasUID(..), HasChunkRefs(..))

import Language.Drasil.Chunk.Concept (cw, dcc, dccWDS)
import Language.Drasil.Chunk.DefinedQuantity (DefinedQuantityDict, dqd, dqd', dqdWr, dqdNoUnit)
Expand Down Expand Up @@ -40,6 +40,8 @@ makeLenses ''ConstrConcept

-- | Finds 'UID' of the 'DefinedQuantityDict' used to make the 'ConstrConcept'.
instance HasUID ConstrConcept where uid = defq . uid
instance HasChunkRefs ConstrConcept where
chunkRefs = const mempty -- FIXME: `chunkRefs` should actually collect the referenced chunks.
-- | Finds term ('NP') of the 'DefinedQuantityDict' used to make the 'ConstrConcept'.
instance NamedIdea ConstrConcept where term = defq . term
-- | Finds the idea contained in the 'DefinedQuantityDict' used to make the 'ConstrConcept'.
Expand Down
25 changes: 14 additions & 11 deletions code/drasil-lang/lib/Language/Drasil/Chunk/Eq.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ module Language.Drasil.Chunk.Eq (
) where

import Control.Lens ((^.), view, lens, Lens', to)
import Drasil.Database (UID, HasUID(..))
import Data.Typeable (Typeable)
import Drasil.Database (UID, HasUID(..), HasChunkRefs(..), IsChunk)

import Language.Drasil.Chunk.UnitDefn (unitWrapper, MayHaveUnit(getUnit), UnitDefn)
import Language.Drasil.Symbol (HasSymbol(symbol), Symbol)
Expand Down Expand Up @@ -50,17 +51,19 @@ qdExpr :: Lens' (QDefinition e) e
qdExpr = lens (\(QD _ _ e) -> e) (\(QD qua ins _) e' -> QD qua ins e')

instance HasUID (QDefinition e) where uid = qdQua . uid
instance NamedIdea (QDefinition e) where term = qdQua . term
instance Idea (QDefinition e) where getA = getA . (^. qdQua)
instance HasChunkRefs (QDefinition e) where
chunkRefs = const mempty -- FIXME: `chunkRefs` should actually collect the referenced chunks.
instance Typeable e => NamedIdea (QDefinition e) where term = qdQua . term
instance Typeable e => Idea (QDefinition e) where getA = getA . (^. qdQua)
instance DefinesQuantity (QDefinition e) where defLhs = qdQua . to dqdWr
instance HasSpace (QDefinition e) where typ = qdQua . typ
instance HasSymbol (QDefinition e) where symbol = symbol . (^. qdQua)
instance Definition (QDefinition e) where defn = qdQua . defn
instance Quantity (QDefinition e) where
instance Typeable e => Quantity (QDefinition e) where
instance Eq (QDefinition e) where a == b = a ^. uid == b ^. uid
instance MayHaveUnit (QDefinition e) where getUnit = getUnit . view qdQua
instance DefiningExpr QDefinition where defnExpr = qdExpr
instance Express e => Express (QDefinition e) where
instance (Express e, Typeable e) => Express (QDefinition e) where
express q = f $ express $ q ^. defnExpr
where
f = case q ^. qdInputs of
Expand Down Expand Up @@ -129,8 +132,8 @@ ec :: (Quantity c, MayHaveUnit c) => c -> e -> QDefinition e
ec c = QD (dqd' (cc' c EmptyS) (symbol c) (c ^. typ) (getUnit c)) []

-- | Factored version of 'QDefinition' functions.
mkFuncDef0 :: (HasUID f, HasSymbol f, HasSpace f,
HasUID i, HasSymbol i, HasSpace i) =>
mkFuncDef0 :: (IsChunk f, HasSymbol f, HasSpace f,
IsChunk i, HasSymbol i, HasSpace i) =>
f -> NP -> Sentence -> Maybe UnitDefn -> [i] -> e -> QDefinition e
mkFuncDef0 f n s u is = QD
(dqd' (cc' (ncUID (f ^. uid) n) s) (symbol f)
Expand All @@ -139,16 +142,16 @@ mkFuncDef0 f n s u is = QD

-- | Create a 'QDefinition' function with a symbol, name, term, list of inputs,
-- resultant units, and a defining Expr
mkFuncDef :: (HasUID f, HasSymbol f, HasSpace f,
HasUID i, HasSymbol i, HasSpace i,
mkFuncDef :: (IsChunk f, HasSymbol f, HasSpace f,
IsChunk i, HasSymbol i, HasSpace i,
IsUnit u) =>
f -> NP -> Sentence -> u -> [i] -> e -> QDefinition e
mkFuncDef f n s u = mkFuncDef0 f n s (Just $ unitWrapper u)

-- | Create a 'QDefinition' function with a symbol, name, term, list of inputs,
-- and a defining Expr
mkFuncDef' :: (HasUID f, HasSymbol f, HasSpace f,
HasUID i, HasSymbol i, HasSpace i) =>
mkFuncDef' :: (IsChunk f, HasSymbol f, HasSpace f,
IsChunk i, HasSymbol i, HasSpace i) =>
f -> NP -> Sentence -> [i] -> e -> QDefinition e
mkFuncDef' f n s = mkFuncDef0 f n s Nothing

Expand Down
4 changes: 2 additions & 2 deletions code/drasil-lang/lib/Language/Drasil/Chunk/NamedIdea.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ module Language.Drasil.Chunk.NamedIdea (

import Control.Lens ((^.), makeLenses, Lens')

import Drasil.Database (mkUid, UID, HasUID(..), declareHasChunkRefs, Generically(..))
import Drasil.Database (mkUid, UID, HasUID(..), IsChunk, declareHasChunkRefs, Generically(..))
import Language.Drasil.NounPhrase.Types (NP)

-- TODO: Why does a NamedIdea need a UID? It might need a UID to be registered in the chunk map.
-- | A NamedIdea is a 'term' that we've identified (has a 'UID') as
-- being worthy of naming.
class HasUID c => NamedIdea c where
class IsChunk c => NamedIdea c where
-- | Lens to the term (a noun phrase).
term :: Lens' c NP

Expand Down
4 changes: 3 additions & 1 deletion code/drasil-lang/lib/Language/Drasil/Chunk/Relation.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module Language.Drasil.Chunk.Relation (

import Control.Lens (makeLenses, (^.), view)

import Drasil.Database (HasUID(..))
import Drasil.Database (HasUID(..), HasChunkRefs(..))

import Language.Drasil.Chunk.Concept (ConceptChunk, dccWDS)
import Language.Drasil.Classes (Express(..),
Expand All @@ -27,6 +27,8 @@ makeLenses ''RelationConcept

-- | Finds the 'UID' of the 'ConceptChunk' used to make the 'RelationConcept'.
instance HasUID RelationConcept where uid = conc . uid
instance HasChunkRefs RelationConcept where
chunkRefs = const mempty -- FIXME: `chunkRefs` should actually collect the referenced chunks.
-- | Equal if 'UID's are equal.
instance Eq RelationConcept where a == b = (a ^. uid) == (b ^. uid)
-- | Finds the term ('NP') of the 'ConceptChunk' used to make the 'RelationConcept'.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module Language.Drasil.Chunk.UncertainQuantity (

import Control.Lens ((^.), makeLenses, view)

import Drasil.Database (HasUID(..))
import Drasil.Database (HasUID(..), HasChunkRefs(..))

import Language.Drasil.Chunk.DefinedQuantity (dqdWr)
import Language.Drasil.Chunk.Constrained (ConstrConcept(..), cuc')
Expand All @@ -36,6 +36,8 @@ makeLenses ''UncertQ
instance Eq UncertQ where a == b = (a ^. uid) == (b ^. uid)
-- | Finds 'UID' of the 'ConstrConcept' used to make the 'UncertQ'.
instance HasUID UncertQ where uid = coco . uid
instance HasChunkRefs UncertQ where
chunkRefs = const mempty -- FIXME: `chunkRefs` should actually collect the referenced chunks.
-- | Finds term ('NP') of the 'ConstrConcept' used to make the 'UncertQ'.
instance NamedIdea UncertQ where term = coco . term
-- | Finds the idea contained in the 'ConstrConcept' used to make the 'UncertQ'.
Expand Down
4 changes: 3 additions & 1 deletion code/drasil-lang/lib/Language/Drasil/Chunk/Unital.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module Language.Drasil.Chunk.Unital (

import Control.Lens (makeLenses, view, (^.))

import Drasil.Database (HasUID(..))
import Drasil.Database (HasUID(..), HasChunkRefs(..))

import Language.Drasil.Chunk.Concept (dccWDS,cw)
import Language.Drasil.Chunk.DefinedQuantity (DefinedQuantityDict, dqd, dqd', dqdWr)
Expand All @@ -35,6 +35,8 @@ makeLenses ''UnitalChunk

-- | Finds 'UID' of the 'DefinedQuantityDict' used to make the 'UnitalChunk'.
instance HasUID UnitalChunk where uid = defq' . uid
instance HasChunkRefs UnitalChunk where
chunkRefs = const mempty -- FIXME: `chunkRefs` should actually collect the referenced chunks.
-- | Finds term ('NP') of the 'DefinedQuantityDict' used to make the 'UnitalChunk'.
instance NamedIdea UnitalChunk where term = defq' . term
-- | Finds the idea contained in the 'DefinedQuantityDict' used to make the 'UnitalChunk'.
Expand Down
8 changes: 5 additions & 3 deletions code/drasil-lang/lib/Language/Drasil/DecoratedReference.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module Language.Drasil.DecoratedReference (

import Control.Lens ((^.), makeLenses, Lens')

import Drasil.Database (HasUID(..))
import Drasil.Database (HasUID(..), IsChunk, HasChunkRefs(..))

import Language.Drasil.Sentence (RefInfo(..))
import Language.Drasil.Reference (Reference, ref)
Expand All @@ -34,15 +34,17 @@ class HasDecRef c where
instance Eq DecRef where a == b = (a ^. uid) == (b ^. uid)
-- | Finds the 'UID' of a 'Reference'.
instance HasUID DecRef where uid = rf . uid
instance HasChunkRefs DecRef where
chunkRefs = const mempty -- FIXME: `chunkRefs` should actually collect the referenced chunks.
-- | Finds the reference address contained in a 'Reference' (through a 'LblType').
instance HasRefAddress DecRef where getRefAdd (DR r _) = getRefAdd r
-- | Finds the shortname of the reference address used for the 'Reference'.
instance HasShortName DecRef where shortname (DR r _) = shortname r

-- | For creating a decorated reference ('DecRef') with extra reference information ('RefInfo').
dRefInfo :: (HasUID r, HasRefAddress r, HasShortName r) => r -> RefInfo -> DecRef
dRefInfo :: (IsChunk r, HasRefAddress r, HasShortName r) => r -> RefInfo -> DecRef
dRefInfo r = DR (ref r)

-- | Same as 'ref', but for 'DecRef' instead of 'Reference'.
dRef :: (HasUID r, HasRefAddress r, HasShortName r) => r -> DecRef
dRef :: (IsChunk r, HasRefAddress r, HasShortName r) => r -> DecRef
dRef r = dRefInfo r None
4 changes: 3 additions & 1 deletion code/drasil-lang/lib/Language/Drasil/Document.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Language.Drasil.Document where

import Control.Lens ((^.), makeLenses, view)

import Drasil.Database (UID, HasUID(..), (+++.), mkUid, nsUid)
import Drasil.Database (UID, HasUID(..), HasChunkRefs(..), (+++.), mkUid, nsUid)
import Utils.Drasil (repUnd)

import Language.Drasil.ShortName (HasShortName(..), ShortName, shortname')
Expand Down Expand Up @@ -48,6 +48,8 @@ data Content = Content Contents
-}
-- | Finds the 'UID' of a 'Section'.
instance HasUID Section where uid = lab . uid
instance HasChunkRefs Section where
chunkRefs = const mempty -- FIXME: `chunkRefs` should actually collect the referenced chunks.
-- | 'Section's are equal if 'UID's are equal.
instance Eq Section where a == b = a ^. uid == b ^. uid
-- | Finds the short name of a 'Section'.
Expand Down
12 changes: 6 additions & 6 deletions code/drasil-lang/lib/Language/Drasil/Expr/Class.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module Language.Drasil.Expr.Class (
import Prelude hiding (sqrt, log, sin, cos, tan, exp)
import Control.Lens ((^.))

import Drasil.Database (HasUID(..))
import Drasil.Database (HasUID(uid), IsChunk)
import Utils.Drasil (toColumn)

import Language.Drasil.Symbol
Expand Down Expand Up @@ -48,11 +48,11 @@ oneThird :: (ExprC r, LiteralC r) => r
oneThird = frac 1 3

-- | Similar to 'apply', but converts second argument into 'Symbol's.
apply1 :: (ExprC r, HasUID f, HasSymbol f, HasUID a, HasSymbol a) => f -> a -> r
apply1 :: (ExprC r, IsChunk f, HasSymbol f, IsChunk a, HasSymbol a) => f -> a -> r
apply1 f a = apply f [sy a]

-- | Similar to 'apply', but the applied function takes two parameters (which are both 'Symbol's).
apply2 :: (ExprC r, HasUID f, HasSymbol f, HasUID a, HasSymbol a, HasUID b, HasSymbol b)
apply2 :: (ExprC r, IsChunk f, HasSymbol f, IsChunk a, HasSymbol a, IsChunk b, HasSymbol b)
=> f -> a -> b -> r
apply2 f a b = apply f [sy a, sy b]

Expand Down Expand Up @@ -185,7 +185,7 @@ class ExprC r where
defint, defsum, defprod :: Symbol -> r -> r -> r -> r

-- | Smart constructor for 'real interval' membership.
realInterval :: HasUID c => c -> RealInterval r r -> r
realInterval :: IsChunk c => c -> RealInterval r r -> r

-- | Euclidean function : takes a vector and returns the sqrt of the sum-of-squares.
euclidean :: [r] -> r
Expand Down Expand Up @@ -215,11 +215,11 @@ class ExprC r where
set' :: Space -> [r] -> r

-- | Applies a given function with a list of parameters.
apply :: (HasUID f, HasSymbol f) => f -> [r] -> r
apply :: (IsChunk f, HasSymbol f) => f -> [r] -> r

-- Note how |sy| 'enforces' having a symbol
-- | Create an 'Expr' from a 'Symbol'ic Chunk.
sy :: (HasUID c, HasSymbol c) => c -> r
sy :: (IsChunk c, HasSymbol c) => c -> r

-- Useful synonym
type PExpr = forall r . (ExprC r, LiteralC r) => r
Expand Down
4 changes: 2 additions & 2 deletions code/drasil-lang/lib/Language/Drasil/Label/Type.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module Language.Drasil.Label.Type(
, name, (+::+), raw, defer, prepend
) where

import Drasil.Database (UID, HasUID)
import Drasil.Database (UID, IsChunk)

-- | Applying different pieces of information for a reference.
-- An RP is a decorated internal reference.
Expand All @@ -35,7 +35,7 @@ class HasRefAddress b where
getRefAdd :: b -> LblType

-- | Members of this class have the ability to be referenced.
class (HasUID s, HasRefAddress s) => Referable s where
class (IsChunk s, HasRefAddress s) => Referable s where
-- | The referencing address (what we're linking to).
-- Only visible in the source (tex/html).
refAdd :: s -> String
Expand Down
6 changes: 3 additions & 3 deletions code/drasil-lang/lib/Language/Drasil/ModelExpr/Class.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Language.Drasil.ModelExpr.Class where
import Prelude hiding (sqrt, log, sin, cos, tan, exp)
import Control.Lens ((^.))

import Drasil.Database (HasUID(..))
import Drasil.Database (HasUID(uid), IsChunk)

import Language.Drasil.Expr.Lang (AssocArithOper(..))
import Language.Drasil.ModelExpr.Lang (ModelExpr(..), DerivType(..),
Expand All @@ -30,10 +30,10 @@ assocSanitize b (de:des) = de : assocSanitize b des
class ModelExprC r where
-- This also wants a symbol constraint.
-- | Gets the derivative of an 'ModelExpr' with respect to a 'Symbol'.
deriv, pderiv :: (HasUID c, HasSymbol c) => r -> c -> r
deriv, pderiv :: (IsChunk c, HasSymbol c) => r -> c -> r

-- | Gets the nthderivative of an 'ModelExpr' with respect to a 'Symbol'.
nthderiv, nthpderiv :: (HasUID c, HasSymbol c) => Integer -> r -> c -> r
nthderiv, nthpderiv :: (IsChunk c, HasSymbol c) => Integer -> r -> c -> r

-- | One expression is "defined" by another.
defines :: r -> r -> r
Expand Down
Loading
Loading