Copyright | (c) 2019-2021 Rudy Matela |
---|---|
License | 3-Clause BSD (see the file LICENSE) |
Maintainer | Rudy Matela <rudy@matela.com.br> |
Safe Haskell | None |
Language | Haskell2010 |
Defines some Expr
fixtures to facilitate testing and playing around on
the REPL (GHCI).
Instead of having to write:
> value "&&" (&&) :$ (value "not" not :$ val True) :$ val False not True && False :: Bool
Using this module, we can just write:
> not' true -&&- false not True && False :: Bool
Instead of having to write:
> value "+" ((+)::Int->Int->Int) :$ (value "*" ((*)::Int->Int->Int) :$ var "x" (undefined::Int) :$ var "y" (undefined::Int)) :$ (value "*" ((*)::Int->Int->Int) :$ val (1::Int) :$ val (2::Int)) x * y + 1 * 2 :: Int
Using this module, we can just write:
> xx -*- yy -+- one -*- two x * y + 1 * 2 :: Int
Instead of having to write:
> value "||" (||) :$ (value "==" ((==)::Int->Int->Bool) :$ val (3::Int) :$ (value "+" ((+)::Int->Int->Int) :$ var "y" (undefined::Int) :$ val (1::Int))) :$ (value "not" not :$ val False) 3 == y + 1 || not False :: Bool
We can just write:
> (three -==- yy -+- one) -||- not' false x == y + 1 || not False :: Bool
This exports over a hundred symbols to be used mainly when writing unit tests or playing around on GHCi.
Since the Expr
type only allows monomorphic values,
encoded polimorphic values are monomorphized
usually to the Int
type.
Beware: lifted Expr
functions sometimes work for different types.
The current version does not have a rationale for types that are included:
you have to either try around on the REPL or look at the source to really know.
Synopsis
- module Data.Express
- b_ :: Expr
- pp :: Expr
- qq :: Expr
- rr :: Expr
- pp' :: Expr
- false :: Expr
- true :: Expr
- notE :: Expr
- orE :: Expr
- andE :: Expr
- implies :: Expr
- not' :: Expr -> Expr
- (-||-) :: Expr -> Expr -> Expr
- (-&&-) :: Expr -> Expr -> Expr
- (-==>-) :: Expr -> Expr -> Expr
- (-==-) :: Expr -> Expr -> Expr
- (-/=-) :: Expr -> Expr -> Expr
- (-<=-) :: Expr -> Expr -> Expr
- (-<-) :: Expr -> Expr -> Expr
- compare' :: Expr -> Expr -> Expr
- if' :: Expr -> Expr -> Expr -> Expr
- i_ :: Expr
- xx :: Expr
- yy :: Expr
- zz :: Expr
- xx' :: Expr
- ii :: Expr
- jj :: Expr
- kk :: Expr
- ii' :: Expr
- zero :: Expr
- one :: Expr
- two :: Expr
- three :: Expr
- minusOne :: Expr
- minusTwo :: Expr
- idE :: Expr
- negateE :: Expr
- absE :: Expr
- idInt :: Expr
- idBool :: Expr
- idChar :: Expr
- idInts :: Expr
- idBools :: Expr
- idString :: Expr
- id' :: Expr -> Expr
- const' :: Expr -> Expr -> Expr
- negate' :: Expr -> Expr
- abs' :: Expr -> Expr
- plus :: Expr
- times :: Expr
- (-+-) :: Expr -> Expr -> Expr
- (-*-) :: Expr -> Expr -> Expr
- ff :: Expr -> Expr
- ffE :: Expr
- gg :: Expr -> Expr
- ggE :: Expr
- (-?-) :: Expr -> Expr -> Expr
- (-$-) :: Expr -> Expr -> Expr
- odd' :: Expr -> Expr
- even' :: Expr -> Expr
- c_ :: Expr
- cc :: Expr
- dd :: Expr
- ccs :: Expr
- ae :: Expr
- bee :: Expr
- cee :: Expr
- dee :: Expr
- space :: Expr
- lineBreak :: Expr
- ord' :: Expr -> Expr
- ordE :: Expr
- is_ :: Expr
- xxs :: Expr
- yys :: Expr
- nil :: Expr
- emptyString :: Expr
- nilInt :: Expr
- nilBool :: Expr
- nilChar :: Expr
- cons :: Expr
- consInt :: Expr
- consBool :: Expr
- consChar :: Expr
- (-:-) :: Expr -> Expr -> Expr
- unit :: Expr -> Expr
- (-++-) :: Expr -> Expr -> Expr
- head' :: Expr -> Expr
- tail' :: Expr -> Expr
- null' :: Expr -> Expr
- length' :: Expr -> Expr
- elem' :: Expr -> Expr -> Expr
- sort' :: Expr -> Expr
- insert' :: Expr -> Expr -> Expr
- nothing :: Expr
- nothingInt :: Expr
- nothingBool :: Expr
- just :: Expr -> Expr
- justInt :: Expr
- justBool :: Expr
- comma :: Expr
- pair :: Expr -> Expr -> Expr
- (-|-) :: Expr -> Expr -> Expr
- triple :: Expr -> Expr -> Expr -> Expr
- quadruple :: Expr -> Expr -> Expr -> Expr -> Expr
- quintuple :: Expr -> Expr -> Expr -> Expr -> Expr -> Expr
- sixtuple :: Expr -> Expr -> Expr -> Expr -> Expr -> Expr -> Expr
Convenience re-export
module Data.Express
Functions and values encoded as Expr or functions of Exprs
The naming rules are:
Int
s are encoded using their English names, e.g.:zero
,one
,two
;Char
s are encoded using their English names, e.g.:bee
,cee
,dee
;- 0-argument constructors are encoded in lowercase,
e.g.:
false
,true
,nothing
,just
; - lifted constructors are lowercased,
e.g.:
just
; - lifted functions are primed
e.g.:
id'
,negate'
,head'
; - lifted operators are surrounded by dashes,
e.g.:
-+-
,-*-
,-&&-
,-||-
,-:-
. - operators are encoded using their English names,
e.g.:
plus
,times
,cons
; - encoded functions are followed by
E
, e.g.:idE
,notE
,absE
; - variables have the first character duplicated,
e.g.:
xx
,yy
,xxs
; - encoded values may have the element type appended,
e.g.:
idInt
,idBool
,justInt
,nilChar
.
Unqualified polymorphic constructors and functions
have their element types bound to Int
.
There are exceptions to the above rules such as:
when a name would conflict with a Prelude function.
(e.g.: orE
and andE
)
Booleans
if' :: Expr -> Expr -> Expr -> Expr Source #
A virtual function if :: Bool -> a -> a -> a
lifted over the Expr
type.
This is displayed as an if-then-else.
> if' pp zero xx (if p then 0 else x) :: Int
> zz -*- if' pp xx yy z * (if p then x else y) :: Int
> if' pp false true -||- if' qq true false (if p then False else True) || (if q then True else False) :: Bool
> evl $ if' true (val 't') (val 'f') :: Char 't'
Integers
A variable function f
of 'Int -> Int' type lifted over the Expr
type.
> ff xx f x :: Int
> ff one f 1 :: Int
A variable function g
of 'Int -> Int' type lifted over the Expr
type.
> gg yy g y :: Int
> gg minusTwo gg (-2) :: Int
Chars
Lists
Maybes
nothingInt :: Expr Source #
nothingBool :: Expr Source #