License | BSD-3-Clause |
---|---|
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
A requirement is something that is needed in order to successfully build a robot running a certain program.
Synopsis
- data Requirement
- data Requirements = Requirements {}
- singleton :: Requirement -> Requirements
- singletonCap :: Capability -> Requirements
- singletonDev :: Text -> Requirements
- singletonInv :: Int -> Text -> Requirements
- insert :: Requirement -> Requirements -> Requirements
- type ReqCtx = Ctx Requirements
- requirements :: ReqCtx -> Term -> (Requirements, ReqCtx)
Requirements
The Requirement
type
data Requirement Source #
A requirement is something a robot must have when it is
built. There are three types:
- A robot can require a certain Capability
, which should be fulfilled
by equipping an appropriate device.
- A robot can require a specific device, which should be equipped.
- A robot can require some number of a specific entity in its inventory.
ReqCap Capability | Require a specific capability. This must be fulfilled by equipping an appropriate device. Requiring the same capability multiple times is the same as requiring it once. |
ReqDev Text | Require a specific device to be equipped. Note that at this
point it is only a name, and has not been resolved to an actual
Requiring the same device multiple times is the same as requiring it once. |
ReqInv Int Text | Require a certain number of a specific entity to be available
in the inventory. The same comments apply re: resolving the
entity name to an actual Inventory requirements are additive, that is, say, requiring 5
of entity |
Instances
The Requirements
type and utility functions
data Requirements Source #
It is tempting to define Requirements = Set Requirement
, but
that would be wrong, since two identical ReqInv
should have
their counts added rather than simply being deduplicated.
Since we will eventually need to deal with the different types of requirements separately, it makes sense to store them separately anyway.
Instances
singleton :: Requirement -> Requirements Source #
Create a Requirements
set with a single Requirement
.
singletonCap :: Capability -> Requirements Source #
For convenience, create a Requirements
set with a single
Capability
requirement.
singletonDev :: Text -> Requirements Source #
For convenience, create a Requirements
set with a single
device requirement.
singletonInv :: Int -> Text -> Requirements Source #
For convenience, create a Requirements
set with a single
inventory requirement.
insert :: Requirement -> Requirements -> Requirements Source #
type ReqCtx = Ctx Requirements Source #
A requirement context records the requirements for the definitions bound to variables.
Requirements analysis
requirements :: ReqCtx -> Term -> (Requirements, ReqCtx) Source #
Analyze a program to see what capabilities may be needed to
execute it. Also return a capability context mapping from any
variables declared via TDef
to the capabilities needed by
their definitions.
Note that this is necessarily a conservative analysis, especially if the program contains conditional expressions. Some capabilities may end up not being actually needed if certain commands end up not being executed. However, the analysis should be safe in the sense that a robot with the indicated capabilities will always be able to run the given program.