| Safe Haskell | None |
|---|---|
| Language | GHC2021 |
Howl
Description
Synopsis
- data Eval a
- runEval :: Eval a -> IO a
- eval :: Expr -> Eval Expr
- class ToBuiltin f
- newtype Variadic a b = MkVariadic (Seq a -> b)
- def :: ToBuiltin f => Symbol -> f -> Eval ()
- run :: Text -> Eval Expr
- run_ :: Text -> Eval ()
- get :: FilePath -> Eval Expr
- get_ :: FilePath -> Eval ()
- parseExprText :: Text -> Either String Expr
- readExprFile :: MonadIO m => FilePath -> m (Either String Expr)
- class PPrint a where
- data Expr
- data Symbol
- data Literal
- = LitNumeric !Numeric
- | LitString !Text
- data Numeric
- type BigFloat = Rounded
- class FromExpr a where
- class ToExpr a where
- pattern List :: Expr
- pattern Plus :: Expr
- pattern Times :: Expr
- pattern Power :: Expr
- pattern Rule :: Expr
- pattern RuleDelayed :: Expr
- pattern Null :: Expr
- pattern (:@) :: Expr -> Seq Expr -> Expr
Running Howl Programs
The monad in which Howl evaluation runs.
An Eval computation has access to the current evaluation context,
including symbol definitions, attributes, line-number state, and
output/error handlers.
Instances
| MonadIO Eval # | |
Defined in Howl.Eval.Context | |
| MonadCatch Eval # | |
Defined in Howl.Eval.Context | |
| MonadMask Eval # | |
Defined in Howl.Eval.Context Methods mask :: HasCallStack => ((forall a. Eval a -> Eval a) -> Eval b) -> Eval b # uninterruptibleMask :: HasCallStack => ((forall a. Eval a -> Eval a) -> Eval b) -> Eval b # generalBracket :: HasCallStack => Eval a -> (a -> ExitCase b -> Eval c) -> (a -> Eval b) -> Eval (b, c) # | |
| MonadThrow Eval # | |
Defined in Howl.Eval.Context Methods throwM :: (HasCallStack, Exception e) => e -> Eval a # | |
| Applicative Eval # | |
| Functor Eval # | |
| Monad Eval # | |
| MonadFail Eval # | |
Defined in Howl.Eval.Context | |
| MonadReader Context Eval # | |
| ToExpr a => ToBuiltin (Eval (Maybe a)) # | A monadic builtin that may fail to match its arguments, signified
by |
| ToExpr a => ToBuiltin (Eval a) # | A monadic builtin that always matches its arguments. |
| (FromExpr a, ToExpr b) => ToBuiltin (Variadic a (Eval (Maybe b))) # | A variadic monadic builtin that may fail to match its arguments,
signified by |
| (FromExpr a, ToExpr b) => ToBuiltin (Variadic a (Eval b)) # | A variadic monadic builtin that always matches its arguments. |
Create a new context, initialize it with the standard builtins
using addBuiltins, and run the Eval computation in that context.
Defining Builtins From Haskell
Given a function type f, turn it into an operation on a
Seq Expr, interpreted as the arguments to a symbolic function.
We provide instances for return types that can reasonably be turned
into rules, where the final result type is any instance of
ToExpr.
Minimal complete definition
Instances
| ToExpr a => ToBuiltin a # | A pure builtin that always matches its arguments. |
| ToExpr a => ToBuiltin (Eval (Maybe a)) # | A monadic builtin that may fail to match its arguments, signified
by |
| ToExpr a => ToBuiltin (Eval a) # | A monadic builtin that always matches its arguments. |
| ToExpr a => ToBuiltin (Maybe a) # | A pure builtin that may fail to match its arguments, signified by
|
| (FromExpr a, ToExpr b) => ToBuiltin (Variadic a (Eval (Maybe b))) # | A variadic monadic builtin that may fail to match its arguments,
signified by |
| (FromExpr a, ToExpr b) => ToBuiltin (Variadic a (Eval b)) # | A variadic monadic builtin that always matches its arguments. |
| (FromExpr a, ToExpr b) => ToBuiltin (Variadic a (Maybe b)) # | A variadic pure builtin that may fail to match its arguments,
signified by |
| (FromExpr a, ToExpr b) => ToBuiltin (Variadic a b) # | A variadic pure builtin that always matches its arguments. |
| (FromExpr a, ToBuiltin f) => ToBuiltin (a -> f) # | Provide instances for functions of the form
Together, these instances allow us to "lift" most reasonable
Haskell functions to functions that can be used inside rules.
Here are some example types that have instances for
|
Mark a function as variadic, i.e. as taking a Seq a of arbitrary
length as its argument list.
Constructors
| MkVariadic (Seq a -> b) |
Instances
| (FromExpr a, ToExpr b) => ToBuiltin (Variadic a (Eval (Maybe b))) # | A variadic monadic builtin that may fail to match its arguments,
signified by |
| (FromExpr a, ToExpr b) => ToBuiltin (Variadic a (Eval b)) # | A variadic monadic builtin that always matches its arguments. |
| (FromExpr a, ToExpr b) => ToBuiltin (Variadic a (Maybe b)) # | A variadic pure builtin that may fail to match its arguments,
signified by |
| (FromExpr a, ToExpr b) => ToBuiltin (Variadic a b) # | A variadic pure builtin that always matches its arguments. |
def :: ToBuiltin f => Symbol -> f -> Eval () #
Define a builtin rule by converting a Haskell function into a Howl
definition using ToBuiltin.
Parsing and Printing
get :: FilePath -> Eval Expr #
Read, parse, and evaluate an expression from a file. The expression may be a compound expression, e.g. a sequence of semicolon-separated subexpressions.
Read, parse, and evaluate an expression from a file, discarding the result.
readExprFile :: MonadIO m => FilePath -> m (Either String Expr) #
Read and parse an expression from a file.
A class for converting values to a human-readable String.
Instances
| PPrint Rule # | |
Defined in Howl.Eval.Context | |
| PPrint Expr # | |
Defined in Howl.Expr.PPrint | |
| PPrint Literal # | |
Defined in Howl.Expr.Internal | |
| PPrint Numeric # | |
Defined in Howl.Expr.Numeric | |
| PPrint Pat # | |
| PPrint Symbol # | |
Defined in Howl.Symbol.Simple | |
| PPrint Symbol # | |
Defined in Howl.Symbol.Symbolize | |
Core Expression Types
A Wolfram Language expression.
Constructors
| ExprLit !Literal | A literal value such as a number or string. |
| ExprSymbol !Symbol | A symbol expression such as |
| ExprApp !Expr !(Seq Expr) | An application of a head expression to a sequence of arguments. For example:
|
A string-like type with O(1) equality and comparison.
A Symbol represents a string (any Textual, so String, Text, ShortText, ByteString, ShortByteString, etc.)
Just like ShortText, ShortByteString and ByteArray, a Symbol has an optimized memory representation,
directly wrapping a primitive ByteArray#.
Furthermore, a global symbol table keeps track of which values currently exist, ensuring we always deduplicate symbols.
This therefore allows us to:
- Check for equality between symbols in constant-time (using pointer equality)
- Calculate the hash in constant-time (using StableName)
- Keep the memory footprint of repeatedly-seen strings low.
This is very useful if you're frequently comparing strings
and the same strings might come up many times.
It also makes Symbol a great candidate for a key in e.g. a HashMap or HashSet.
The global symbol table is implemented using weak pointers, which means that unused symbols will be garbage collected. As such, you do not need to be concerned about memory leaks (as is the case with many other symbol table implementations).
Symbols are considered 'the same' regardless of whether they originate
from a String, (lazy or strict, normal or short) Text, (lazy or strict, normal or short) ByteString etc.
Instances
| Binary Symbol | Uses the Since: symbolize-1.0.1.0 |
| NFData Symbol | The contents inside a |
| Data Symbol | This Since: symbolize-1.0.1.0 |
Defined in Symbolize Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Symbol -> c Symbol # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Symbol # toConstr :: Symbol -> Constr # dataTypeOf :: Symbol -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Symbol) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Symbol) # gmapT :: (forall b. Data b => b -> b) -> Symbol -> Symbol # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Symbol -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Symbol -> r # gmapQ :: (forall d. Data d => d -> u) -> Symbol -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Symbol -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Symbol -> m Symbol # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Symbol -> m Symbol # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Symbol -> m Symbol # | |
| IsString Symbol | |
Defined in Symbolize Methods fromString :: String -> Symbol # | |
| Read Symbol | To be a good citizen w.r.t both
|
| Show Symbol | |
| Eq Symbol | Equality checking takes only O(1) time, and is a simple pointer-equality check. |
| Ord Symbol | Symbols are ordered by their lexicographical UTF-8 representation. Therefore, comparison takes O(n) time. |
| Hashable Symbol | Hashing a
|
| FromExpr Symbol # | |
| ToExpr Symbol # | |
Defined in Howl.Expr.Internal | |
| PPrint Symbol # | |
Defined in Howl.Symbol.Symbolize | |
A literal value.
Constructors
| LitNumeric !Numeric | A numeric literal. |
| LitString !Text | A string literal. |
A numeric value.
Constructors
| NInteger !Integer | An integer. |
| NRational !Rational | A rational number. |
| NDouble !Double | A double-precision floating-point number. |
| NBigFloat !BigFloat | An MPFR floating-point number with dynamic precision. |
Instances
| Enum Numeric # | |
| Num Numeric # | |
| Fractional Numeric # | |
| Real Numeric # | |
Defined in Howl.Expr.Numeric Methods toRational :: Numeric -> Rational # | |
| RealFrac Numeric # | |
| Show Numeric # | |
| Eq Numeric # | |
| Ord Numeric # | |
| FromExpr Numeric # | |
| ToExpr Numeric # | |
Defined in Howl.Expr.Internal | |
| PPrint Numeric # | |
Defined in Howl.Expr.Numeric | |
A class for types that can potentially be matched to expressions.
Instances
| FromExpr Rational # | |
| FromExpr LHS # | |
| FromExpr Expr # | |
| FromExpr BigFloat # | |
| FromExpr Numeric # | |
| FromExpr Symbol # | |
| FromExpr Text # | |
| FromExpr Integer # | |
| FromExpr () # | |
Defined in Howl.Expr.Syntax | |
| FromExpr Bool # | |
| FromExpr Double # | |
| FromExpr Int # | |
| FromExpr a => FromExpr (AList a) # | |
| FromExpr a => FromExpr (ListOrSolo a) # | |
Defined in Howl.Builtins.Types Methods fromExpr :: Expr -> Maybe (ListOrSolo a) # | |
| FromExpr a => FromExpr [a] # | |
Defined in Howl.Expr.Syntax | |
| (FromExpr a, FromExpr b) => FromExpr (a, b) # | |
Defined in Howl.Expr.Syntax | |
| (FromExpr a, FromExpr b, FromExpr c) => FromExpr (a, b, c) # | |
Defined in Howl.Expr.Syntax | |
| (FromExpr a, FromExpr b, FromExpr c, FromExpr d) => FromExpr (a, b, c, d) # | |
Defined in Howl.Expr.Syntax | |
A class for types that can be converted to expressions.
Instances
| ToExpr Rational # | Convert a Rational into an Expr, representing it as an ExprInteger if it is an integer. |
Defined in Howl.Expr.Internal | |
| ToExpr Expr # | |
Defined in Howl.Expr.Internal | |
| ToExpr BigFloat # | |
Defined in Howl.Expr.Internal | |
| ToExpr Numeric # | |
Defined in Howl.Expr.Internal | |
| ToExpr Symbol # | |
Defined in Howl.Expr.Internal | |
| ToExpr Text # | |
Defined in Howl.Expr.Internal | |
| ToExpr Integer # | |
Defined in Howl.Expr.Internal | |
| ToExpr () # | |
Defined in Howl.Expr.Syntax | |
| ToExpr Bool # | |
Defined in Howl.Expr.Syntax | |
| ToExpr Double # | |
Defined in Howl.Expr.Internal | |
| ToExpr Int # | |
Defined in Howl.Expr.Internal | |
| ToExpr a => ToExpr (AList a) # | |
Defined in Howl.Builtins.Types | |
| ToExpr a => ToExpr [a] # | |
Defined in Howl.Expr.Syntax | |
| (ToExpr a, ToExpr b) => ToExpr (a, b) # | |
Defined in Howl.Expr.Syntax | |
| (ToExpr a, ToExpr b, ToExpr c) => ToExpr (a, b, c) # | |
Defined in Howl.Expr.Syntax | |
| (ToExpr a, ToExpr b, ToExpr c, ToExpr d) => ToExpr (a, b, c, d) # | |
Defined in Howl.Expr.Syntax | |
Common Expression Patterns
pattern RuleDelayed :: Expr #