Copyright | Brent Yorgey |
---|---|
License | BSD-3-Clause |
Maintainer | byorgey@gmail.com |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Abstract syntax for terms of the Swarm programming language.
Synopsis
- data Direction
- data AbsoluteDir
- data RelativeDir
- data DirInfo = DirInfo {
- dirSyntax :: Text
- dirApplyTurn :: Heading -> Heading
- applyTurn :: Direction -> Heading -> Heading
- toDirection :: Heading -> Maybe Direction
- fromDirection :: Direction -> Heading
- allDirs :: [Direction]
- isCardinal :: Direction -> Bool
- dirInfo :: Direction -> DirInfo
- north :: Heading
- south :: Heading
- east :: Heading
- west :: Heading
- data Const
- = Noop
- | Wait
- | Selfdestruct
- | Move
- | Turn
- | Grab
- | Harvest
- | Place
- | Give
- | Equip
- | Unequip
- | Make
- | Has
- | Equipped
- | Count
- | Drill
- | Build
- | Salvage
- | Reprogram
- | Say
- | Listen
- | Log
- | View
- | Appear
- | Create
- | Time
- | Whereami
- | Heading
- | Blocked
- | Scan
- | Upload
- | Ishere
- | Isempty
- | Self
- | Parent
- | Base
- | Meet
- | MeetAll
- | Whoami
- | Setname
- | Random
- | Run
- | If
- | Inl
- | Inr
- | Case
- | Fst
- | Snd
- | Force
- | Return
- | Try
- | Undefined
- | Fail
- | Not
- | Neg
- | Eq
- | Neq
- | Lt
- | Gt
- | Leq
- | Geq
- | Or
- | And
- | Add
- | Sub
- | Mul
- | Div
- | Exp
- | Format
- | Concat
- | Chars
- | Split
- | CharAt
- | ToChar
- | AppF
- | Swap
- | Atomic
- | Teleport
- | As
- | RobotNamed
- | RobotNumbered
- | Knows
- allConst :: [Const]
- data ConstInfo = ConstInfo {}
- data ConstDoc = ConstDoc {}
- data ConstMeta
- data MBinAssoc
- data MUnAssoc
- constInfo :: Const -> ConstInfo
- arity :: Const -> Int
- isCmd :: Const -> Bool
- isUserFunc :: Const -> Bool
- isOperator :: Const -> Bool
- isBuiltinFunction :: Const -> Bool
- isTangible :: Const -> Bool
- isLong :: Const -> Bool
- data Syntax' ty = Syntax' {}
- sLoc :: forall ty. Lens' (Syntax' ty) SrcLoc
- sTerm :: forall ty. Lens' (Syntax' ty) (Term' ty)
- sType :: forall ty. Lens' (Syntax' ty) ty
- type Syntax = Syntax' ()
- pattern Syntax :: SrcLoc -> Term -> Syntax
- data LocVar = LV {}
- data SrcLoc
- noLoc :: Term -> Syntax
- pattern STerm :: Term -> Syntax
- pattern TPair :: Term -> Term -> Term
- pattern TLam :: Var -> Maybe Type -> Term -> Term
- pattern TApp :: Term -> Term -> Term
- pattern (:$:) :: Term -> Syntax -> Term
- pattern TLet :: Bool -> Var -> Maybe Polytype -> Term -> Term -> Term
- pattern TDef :: Bool -> Var -> Maybe Polytype -> Term -> Term
- pattern TBind :: Maybe Var -> Term -> Term -> Term
- pattern TDelay :: DelayType -> Term -> Term
- type Var = Text
- data DelayType
- = SimpleDelay
- | MemoizedDelay (Maybe Var)
- data Term' ty
- = TUnit
- | TConst Const
- | TDir Direction
- | TInt Integer
- | TAntiInt Text
- | TText Text
- | TAntiText Text
- | TBool Bool
- | TRobot Int
- | TRef Int
- | TRequireDevice Text
- | TRequire Int Text
- | TVar Var
- | SPair (Syntax' ty) (Syntax' ty)
- | SLam LocVar (Maybe Type) (Syntax' ty)
- | SApp (Syntax' ty) (Syntax' ty)
- | SLet Bool LocVar (Maybe Polytype) (Syntax' ty) (Syntax' ty)
- | SDef Bool LocVar (Maybe Polytype) (Syntax' ty)
- | SBind (Maybe LocVar) (Syntax' ty) (Syntax' ty)
- | SDelay DelayType (Syntax' ty)
- type Term = Term' ()
- mkOp :: Const -> Syntax -> Syntax -> Syntax
- mkOp' :: Const -> Term -> Term -> Term
- unfoldApps :: Syntax' ty -> NonEmpty (Syntax' ty)
- erase :: Term' ty -> Term
- eraseS :: Syntax' ty -> Term
- freeVarsS :: forall ty. Traversal' (Syntax' ty) (Syntax' ty)
- freeVarsT :: forall ty. Traversal' (Syntax' ty) (Term' ty)
- freeVarsV :: Traversal' (Syntax' ty) Var
- mapFreeS :: Var -> (Syntax' ty -> Syntax' ty) -> Syntax' ty -> Syntax' ty
- locVarToSyntax' :: LocVar -> ty -> Syntax' ty
Directions
The type of directions. Used e.g. to indicate which way a robot will turn.
Instances
data AbsoluteDir Source #
An absolute direction is one which is defined with respect to an external frame of reference; robots need a compass in order to use them.
Instances
data RelativeDir Source #
A relative direction is one which is defined with respect to the robot's frame of reference; no special capability is needed to use them.
Instances
toDirection :: Heading -> Maybe Direction Source #
Possibly convert a heading into a Direction
---that is, if the
vector happens to be a unit vector in one of the cardinal
directions.
fromDirection :: Direction -> Heading Source #
Constants
Constants, representing various built-in functions and commands.
IF YOU ADD A NEW CONSTANT, be sure to also update:
1. the constInfo
function (below)
2. the capability checker (Swarm.Language.Capability)
3. the type checker (Swarm.Language.Typecheck)
4. the runtime (Swarm.Game.Step)
5. the emacs mode syntax highlighter (contribs/swarm-mode.el
)
GHC will warn you about incomplete pattern matches for the first
four, and CI will warn you about the last, so in theory it's not
really possible to forget. Note you do not need to update the
parser or pretty-printer, since they are auto-generated from
constInfo
.
Noop | Do nothing. This is different than |
Wait | Wait for a number of time steps without doing anything. |
Selfdestruct | Self-destruct. |
Move | Move forward one step. |
Turn | Turn in some direction. |
Grab | Grab an item from the current location. |
Harvest | Harvest an item from the current location. |
Place | Try to place an item at the current location. |
Give | Give an item to another robot at the current location. |
Equip | Equip a device on oneself. |
Unequip | Unequip an equipped device, returning to inventory. |
Make | Make an item. |
Has | Sense whether we have a certain item. |
Equipped | Sense whether we have a certain device equipped. |
Count | Sense how many of a certain item we have. |
Drill | Drill through an entity. |
Build | Construct a new robot. |
Salvage | Deconstruct an old robot. |
Reprogram | Reprogram a robot that has executed it's command with a new command |
Say | Emit a message. |
Listen | Listen for a message from other robots. |
Log | Emit a log message. |
View | View a certain robot. |
Appear | Set what characters are used for display. |
Create | Create an entity out of thin air. Only available in creative mode. |
Time | Get current time |
Whereami | Get the current x, y coordinates |
Heading | Get the current heading. |
Blocked | See if we can move forward or not. |
Scan | Scan a nearby cell |
Upload | Upload knowledge to another robot |
Ishere | See if a specific entity is here. |
Isempty | Check whether the current cell is empty |
Self | Get a reference to oneself |
Parent | Get the robot's parent |
Base | Get a reference to the base |
Meet | Meet a nearby robot |
MeetAll | Meet all nearby robots |
Whoami | Get the robot's display name |
Setname | Set the robot's display name |
Random | Get a uniformly random integer. |
Run | Run a program loaded from a file. |
If | If-expressions. |
Inl | Left injection. |
Inr | Right injection. |
Case | Case analysis on a sum type. |
Fst | First projection. |
Snd | Second projection. |
Force | Force a delayed evaluation. |
Return | Return for the cmd monad. |
Try | Try/catch block |
Undefined | Undefined |
Fail | User error |
Not | Logical negation. |
Neg | Arithmetic negation. |
Eq | Logical equality comparison |
Neq | Logical unequality comparison |
Lt | Logical lesser-then comparison |
Gt | Logical greater-then comparison |
Leq | Logical lesser-or-equal comparison |
Geq | Logical greater-or-equal comparison |
Or | Logical or. |
And | Logical and. |
Add | Arithmetic addition operator |
Sub | Arithmetic subtraction operator |
Mul | Arithmetic multiplication operator |
Div | Arithmetic division operator |
Exp | Arithmetic exponentiation operator |
Format | Turn an arbitrary value into a string |
Concat | Concatenate string values |
Chars | Count number of characters. |
Split | Split string into two parts. |
CharAt | Get the character at an index. |
ToChar | Create a singleton text value with the given character code. |
AppF | Application operator - helps to avoid parentheses:
|
Swap | Swap placed entity with one in inventory. Essentially atomic grab and place. |
Atomic | When executing |
Teleport | Teleport a robot to the given position. |
As | Run a command as if you were another robot. |
RobotNamed | Find an actor by name. |
RobotNumbered | Find an actor by number. |
Knows | Check if an entity is known. |
Instances
ConstMFunc Int Bool | Function with arity of which some are commands |
ConstMUnOp MUnAssoc | Unary operator with fixity and associativity. |
ConstMBinOp MBinAssoc | Binary operator with fixity and associativity. |
The meta type representing associativity of binary operator.
L | Left associative binary operator (see |
N | Non-associative binary operator (see |
R | Right associative binary operator (see |
The meta type representing associativity of unary operator.
constInfo :: Const -> ConstInfo Source #
Information about constants used in parsing and pretty printing.
It would be more compact to represent the information by testing whether the constants are in certain sets, but using pattern matching gives us warning if we add more constants.
arity :: Const -> Int Source #
The arity of a constant, i.e. how many arguments it expects.
The runtime system will collect arguments to a constant (see
VCApp
) until it has enough, then dispatch
the constant's behavior.
isCmd :: Const -> Bool Source #
Whether a constant represents a command. Constants which are
not commands are functions which are interpreted as soon as
they are evaluated. Commands, on the other hand, are not
interpreted until being executed, that is, when meeting an
FExec
frame. When evaluated, commands simply turn into a
VCApp
.
isUserFunc :: Const -> Bool Source #
Function constants user can call with reserved words (wait
,...).
isOperator :: Const -> Bool Source #
Whether the constant is an operator. Useful predicate for documentation.
isBuiltinFunction :: Const -> Bool Source #
Whether the constant is a function which is interpreted as soon as it is evaluated, but *not* including operators.
Note: This is used for documentation purposes and complements isCmd
and isOperator
in that exactly one will accept a given constant.
isTangible :: Const -> Bool Source #
Whether the constant is a tangible command, that has an external effect on the world. At most one tangible command may be executed per tick.
isLong :: Const -> Bool Source #
Whether the constant is a long command, that is, a tangible
command which could require multiple ticks to execute. Such
commands cannot be allowed in atomic
blocks.
Syntax
The surface syntax for the language, with location and type annotations.
Instances
Foldable Syntax' Source # | |
Defined in Swarm.Language.Syntax fold :: Monoid m => Syntax' m -> m # foldMap :: Monoid m => (a -> m) -> Syntax' a -> m # foldMap' :: Monoid m => (a -> m) -> Syntax' a -> m # foldr :: (a -> b -> b) -> b -> Syntax' a -> b # foldr' :: (a -> b -> b) -> b -> Syntax' a -> b # foldl :: (b -> a -> b) -> b -> Syntax' a -> b # foldl' :: (b -> a -> b) -> b -> Syntax' a -> b # foldr1 :: (a -> a -> a) -> Syntax' a -> a # foldl1 :: (a -> a -> a) -> Syntax' a -> a # elem :: Eq a => a -> Syntax' a -> Bool # maximum :: Ord a => Syntax' a -> a # minimum :: Ord a => Syntax' a -> a # | |
Traversable Syntax' Source # | |
Functor Syntax' Source # | |
FromJSON ty => FromJSON (Syntax' ty) Source # | |
ToJSON ty => ToJSON (Syntax' ty) Source # | |
Defined in Swarm.Language.Syntax | |
Data ty => Data (Syntax' ty) Source # | |
Defined in Swarm.Language.Syntax gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Syntax' ty -> c (Syntax' ty) # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Syntax' ty) # toConstr :: Syntax' ty -> Constr # dataTypeOf :: Syntax' ty -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (Syntax' ty)) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Syntax' ty)) # gmapT :: (forall b. Data b => b -> b) -> Syntax' ty -> Syntax' ty # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Syntax' ty -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Syntax' ty -> r # gmapQ :: (forall d. Data d => d -> u) -> Syntax' ty -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Syntax' ty -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Syntax' ty -> m (Syntax' ty) # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Syntax' ty -> m (Syntax' ty) # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Syntax' ty -> m (Syntax' ty) # | |
Generic (Syntax' ty) Source # | |
Show ty => Show (Syntax' ty) Source # | |
Eq ty => Eq (Syntax' ty) Source # | |
Data ty => Plated (Syntax' ty) Source # | |
Defined in Swarm.Language.Syntax plate :: Traversal' (Syntax' ty) (Syntax' ty) # | |
PrettyPrec (Syntax' ty) Source # | |
Defined in Swarm.Language.Pretty | |
(HasBindings u, Data u) => HasBindings (Syntax' u) Source # | |
Defined in Swarm.Language.Typecheck | |
type Rep (Syntax' ty) Source # | |
Defined in Swarm.Language.Syntax type Rep (Syntax' ty) = D1 ('MetaData "Syntax'" "Swarm.Language.Syntax" "swarm-0.3.0.1-EqejWKaUFCJHRV1d3nJuA2" 'False) (C1 ('MetaCons "Syntax'" 'PrefixI 'True) (S1 ('MetaSel ('Just "_sLoc") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 SrcLoc) :*: (S1 ('MetaSel ('Just "_sTerm") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 (Term' ty)) :*: S1 ('MetaSel ('Just "_sType") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 ty)))) |
A variable with associated source location, used for variable binding sites. (Variable occurrences are a bare TVar which gets wrapped in a Syntax node, so we don't need LocVar for those.)
Instances
FromJSON LocVar Source # | |
ToJSON LocVar Source # | |
Defined in Swarm.Language.Syntax | |
Data LocVar Source # | |
Defined in Swarm.Language.Syntax gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> LocVar -> c LocVar # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c LocVar # toConstr :: LocVar -> Constr # dataTypeOf :: LocVar -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c LocVar) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c LocVar) # gmapT :: (forall b. Data b => b -> b) -> LocVar -> LocVar # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> LocVar -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> LocVar -> r # gmapQ :: (forall d. Data d => d -> u) -> LocVar -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> LocVar -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> LocVar -> m LocVar # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> LocVar -> m LocVar # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> LocVar -> m LocVar # | |
Generic LocVar Source # | |
Show LocVar Source # | |
Eq LocVar Source # | |
Ord LocVar Source # | |
type Rep LocVar Source # | |
Defined in Swarm.Language.Syntax type Rep LocVar = D1 ('MetaData "LocVar" "Swarm.Language.Syntax" "swarm-0.3.0.1-EqejWKaUFCJHRV1d3nJuA2" 'False) (C1 ('MetaCons "LV" 'PrefixI 'True) (S1 ('MetaSel ('Just "lvSrcLoc") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 SrcLoc) :*: S1 ('MetaSel ('Just "lvVar") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 Var))) |
Instances
FromJSON SrcLoc Source # | |
ToJSON SrcLoc Source # | |
Defined in Swarm.Language.Syntax | |
Data SrcLoc Source # | |
Defined in Swarm.Language.Syntax gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> SrcLoc -> c SrcLoc # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c SrcLoc # toConstr :: SrcLoc -> Constr # dataTypeOf :: SrcLoc -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c SrcLoc) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c SrcLoc) # gmapT :: (forall b. Data b => b -> b) -> SrcLoc -> SrcLoc # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> SrcLoc -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> SrcLoc -> r # gmapQ :: (forall d. Data d => d -> u) -> SrcLoc -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> SrcLoc -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> SrcLoc -> m SrcLoc # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> SrcLoc -> m SrcLoc # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> SrcLoc -> m SrcLoc # | |
Monoid SrcLoc Source # | |
Semigroup SrcLoc Source # | |
Generic SrcLoc Source # | |
Show SrcLoc Source # | |
Eq SrcLoc Source # | |
Ord SrcLoc Source # | |
type Rep SrcLoc Source # | |
Defined in Swarm.Language.Syntax type Rep SrcLoc = D1 ('MetaData "SrcLoc" "Swarm.Language.Syntax" "swarm-0.3.0.1-EqejWKaUFCJHRV1d3nJuA2" 'False) (C1 ('MetaCons "NoLoc" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "SrcLoc" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 Int) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 Int))) |
pattern (:$:) :: Term -> Syntax -> Term infixl 0 Source #
Convenient infix pattern synonym for application.
pattern TLet :: Bool -> Var -> Maybe Polytype -> Term -> Term -> Term Source #
Match a TLet without syntax
Terms
Different runtime behaviors for delayed expressions.
SimpleDelay | A simple delay, implemented via a (non-memoized) |
MemoizedDelay (Maybe Var) | A memoized delay, implemented by allocating a mutable cell
with the delayed expression and returning a reference to it.
When the |
Instances
FromJSON DelayType Source # | |
ToJSON DelayType Source # | |
Defined in Swarm.Language.Syntax | |
Data DelayType Source # | |
Defined in Swarm.Language.Syntax gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> DelayType -> c DelayType # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c DelayType # toConstr :: DelayType -> Constr # dataTypeOf :: DelayType -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c DelayType) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c DelayType) # gmapT :: (forall b. Data b => b -> b) -> DelayType -> DelayType # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> DelayType -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> DelayType -> r # gmapQ :: (forall d. Data d => d -> u) -> DelayType -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> DelayType -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> DelayType -> m DelayType # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> DelayType -> m DelayType # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> DelayType -> m DelayType # | |
Generic DelayType Source # | |
Show DelayType Source # | |
Eq DelayType Source # | |
type Rep DelayType Source # | |
Defined in Swarm.Language.Syntax type Rep DelayType = D1 ('MetaData "DelayType" "Swarm.Language.Syntax" "swarm-0.3.0.1-EqejWKaUFCJHRV1d3nJuA2" 'False) (C1 ('MetaCons "SimpleDelay" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "MemoizedDelay" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 (Maybe Var)))) |
Terms of the Swarm language.
TUnit | The unit value. |
TConst Const | A constant. |
TDir Direction | A direction literal. |
TInt Integer | An integer literal. |
TAntiInt Text | An antiquoted Haskell variable name of type Integer. |
TText Text | A text literal. |
TAntiText Text | An antiquoted Haskell variable name of type Text. |
TBool Bool | A Boolean literal. |
TRobot Int | A robot reference. These never show up in surface syntax, but are here so we can factor pretty-printing for Values through pretty-printing for Terms. |
TRef Int | A memory reference. These likewise never show up in surface syntax, but are here to facilitate pretty-printing. |
TRequireDevice Text | Require a specific device to be installed. |
TRequire Int Text | Require a certain number of an entity. |
TVar Var | A variable. |
SPair (Syntax' ty) (Syntax' ty) | A pair. |
SLam LocVar (Maybe Type) (Syntax' ty) | A lambda expression, with or without a type annotation on the binder. |
SApp (Syntax' ty) (Syntax' ty) | Function application. |
SLet Bool LocVar (Maybe Polytype) (Syntax' ty) (Syntax' ty) | A (recursive) let expression, with or without a type
annotation on the variable. The |
SDef Bool LocVar (Maybe Polytype) (Syntax' ty) | A (recursive) definition command, which binds a variable to a
value in subsequent commands. The |
SBind (Maybe LocVar) (Syntax' ty) (Syntax' ty) | A monadic bind for commands, of the form |
SDelay DelayType (Syntax' ty) | Delay evaluation of a term, written |
Instances
mkOp :: Const -> Syntax -> Syntax -> Syntax Source #
COMPLETE pragma tells GHC using this set of pattern is complete for Term
Make infix operation (e.g. 2 + 3
) a curried function
application (((+) 2) 3
).
mkOp' :: Const -> Term -> Term -> Term Source #
Make infix operation, discarding any syntax related location
unfoldApps :: Syntax' ty -> NonEmpty (Syntax' ty) Source #
Turn function application chain into a list.
>>>
syntaxWrap f = fmap (^. sTerm) . f . Syntax NoLoc
>>>
syntaxWrap unfoldApps (mkOp' Mul (TInt 1) (TInt 2)) -- 1 * 2
TConst Mul :| [TInt 1,TInt 2]
Erasure
Term traversal
freeVarsS :: forall ty. Traversal' (Syntax' ty) (Syntax' ty) Source #
Traversal over those subterms of a term which represent free
variables. The S suffix indicates that it is a Traversal
over
the Syntax
nodes (which contain type and source location info)
containing free variables inside a larger Syntax
value. Note
that if you want to get the list of all Syntax
nodes
representing free variables, you can do so via
.toListOf
freeVarsS
mapFreeS :: Var -> (Syntax' ty -> Syntax' ty) -> Syntax' ty -> Syntax' ty Source #
Apply a function to all free occurrences of a particular variable.
locVarToSyntax' :: LocVar -> ty -> Syntax' ty Source #