Safe Haskell | None |
---|---|
Language | Haskell98 |
Rules to convert numbers to an expression language.
- type Rule a = (a -> Exp) -> a -> Exp
- conditional :: (a -> Bool) -> Rule a -> Rule a -> Rule a
- combine :: Rule a -> Rule a -> Rule a
- mapRule :: (a -> a) -> Rule a -> Rule a
- findRule :: (Ord a, Num a) => (a, Rule a) -> [(a, Rule a)] -> a -> Rule a
- unknown :: Rule a
- lit :: Integral a => Rule a
- lit1 :: Integral a => Rule a
- pos :: (Ord a, Num a) => Rule a
- checkPos :: (Ord a, Num a) => Rule a
- add :: Num a => a -> Side -> Rule a
- mul :: Integral a => a -> Side -> Side -> Rule a
- mul1 :: Integral a => a -> Side -> Side -> Rule a
- sub :: Integral a => a -> Rule a
- mulScale_ :: forall a. Integral a => ((a -> Exp) -> a -> Exp -> Side -> Exp) -> a -> a -> Side -> Side -> Rule a -> Rule a
- mulScale :: Integral a => a -> a -> Side -> Side -> Rule a -> Rule a
- mulScale1 :: Integral a => a -> a -> Side -> Side -> Rule a -> Rule a
- shortScale :: Integral a => Side -> Side -> Rule a -> Rule a
- longScale :: Integral a => Side -> Side -> Rule a -> Rule a
- pelletierScale :: Integral a => Side -> Side -> Rule a -> Rule a
- shortScale1 :: Integral a => Side -> Side -> Rule a -> Rule a
- longScale1 :: Integral a => Side -> Side -> Rule a -> Rule a
- pelletierScale1 :: Integral a => Side -> Side -> Rule a -> Rule a
- mkStep :: Integral a => Rule a -> (a -> Side -> Rule a) -> (a -> Side -> Side -> Rule a) -> a -> a -> Side -> Side -> Rule a
- step :: Integral a => a -> a -> Side -> Side -> Rule a
- step1 :: Integral a => a -> a -> Side -> Side -> Rule a
- changeCase :: Maybe Case -> Rule a
- changeGender :: Maybe Gender -> Rule a
- changeNumber :: Maybe Number -> Rule a
The Rule type
type Rule a = (a -> Exp) -> a -> Exp Source #
A rule on how to convert a number into an expression
language. Notice how this type is similar to the type of the $
operator.
Rule combinators
:: (a -> Bool) | Predicate on input value ("if"). |
-> Rule a | Rule to apply when predicate holds ("then"). |
-> Rule a | Rule to apply when predicate does not hold ("else"). |
-> Rule a |
The 'if-then-else' concept for rules. Applies the first rule if the predicate holds on the input value, otherwise applies the second rule.
combine :: Rule a -> Rule a -> Rule a Source #
Tries to apply the first rule, if that produces an Unknown
value it applies the second rule.
:: (Ord a, Num a) | |
=> (a, Rule a) | First interval rule. |
-> [(a, Rule a)] | Interval rule list. |
-> a | Upper bound of the last interval. |
-> Rule a |
Chooses which rule to apply to an input value based on a interval list of rules.
Rules
A rule that always fails to convert a value. It constantly
produces the unknown
value.
>>>
(fix unknown) (3 :: Integer) :: Exp
Unknown
lit :: Integral a => Rule a Source #
The literal rule. Converts its argument into a lit
eral
expression.
>>>
lit (fix unknown) (3 :: Integer) :: Exp
Lit 3
In this example lit is applied to the nonsense rule "fix
unknown
". Lit ignores that function, which is why we can pass it
anything we want, including itself.
>>>
lit (fix undefined) (3 :: Integer) :: Exp
Lit 3>>>
(fix lit) (3 :: Integer) :: Exp
Lit 3
lit1 :: Integral a => Rule a Source #
A variant on the lit
rule which always multiplies its argument
with 1. Useful for languages which have numerals of the form "one
hundred and three" as opposed to "hundred and three".
>>>
lit1 (fix unknown) (3 :: Integer) :: Exp
Mul (Lit 1) (Lit 3)
pos :: (Ord a, Num a) => Rule a Source #
>>>
(pos $ lit $ fix unknown) (3 :: Integer) :: Exp
Lit 3>>>
(pos $ lit $ fix unknown) (-3 :: Integer) :: Exp
Neg (Lit 3)
checkPos :: (Ord a, Num a) => Rule a Source #
>>>
(checkPos $ lit $ fix unknown) (3 :: Integer) :: Exp
Lit 3>>>
(checkPos $ lit $ fix unknown) (-3 :: Integer) :: Exp
Unknown
add :: Num a => a -> Side -> Rule a Source #
>>>
(add 10 L $ lit $ fix unknown) (13 :: Integer) :: Exp
Add (Lit 3) (Lit 10)
mul :: Integral a => a -> Side -> Side -> Rule a Source #
>>>
(mul 10 R L $ lit $ fix unknown) (42 :: Integer) :: Exp
Add (Mul (Lit 4) (Lit 10)) (Lit 2)
sub :: Integral a => a -> Rule a Source #
>>>
(sub 20 $ lit $ fix unknown) (18 :: Integer) :: Exp
Sub (Lit 2) (Lit 20)