Expr = Variable
| Expr Expr (application)
| λ Variable Expr (abstraction)
beta reduction (under capture avoidance)
An expression where no beta-reduction is possible.
An expression has at most 1 beta normal form.
(So it is independent of reduction strategy)
Expr = Variable
| Expr Expr (application)
| λ Variable Expr (abstraction)
| Value (domain elements)
Naming Convention:
Uppercased constructors
Lowercased variables
(\x -> Pair x x) 7
Pair 7 7
Problem: No way to talk about real values
Example
Expr = Variable
| Expr Expr (application)
| λ Variable Expr (abstraction)
| Value (domain elements)
| case Expr [(Pattern,Expr)] (pattern match)
Problem: No way to deconstruct values
Pattern = Variable (bring variable into scope)
| Value [Pattern] (Constructor)
| _ (don't care, universal match)
(Extensions for better pattern matches are well-known, but mostly syntactic sugar)
\x -> (case x of (Pair y z -> y) ; _ -> x) (Pair 1 2)
1
Example
Expr = Variable
| Expr Expr (application)
| λ Variable Expr (abstraction)
| Value (domain elements)
| case Expr [(Pattern,Expr)] (pattern match)
| let Variable Expr Expr
Problem: No way to reuse values
Pattern = Variable (bring variable into scope)
| Value [Pattern] (Constructor)
| _ (don't care, universal match)
let ifThenElse = (\x y z -> case x of
True -> y
False -> z
) in
ifThenElse (jarig Jan) "hoera" "hallo"
Example
let ifThenElse = (\x y z -> case x of
True -> y
False -> z
) in
ifThenElse (jarig Jan) "hoera" "hallo"
Example
Expressions with a beta-normal form without lambda abstraction, can be translated into ASP
Not very interesting -> ASP does no work.
Can't reason without defining all interpretations
(We just rebuilt a Core fragment of
a functional language)
type CoreExpr = Expr Var
data Expr b -- "b" for the type of binders,
= Var Id
| Lit Literal
| App (Expr b) (Arg b)
| Lam b (Expr b)
| Let (Bind b) (Expr b)
| Case (Expr b) b Type [Alt b]
| Cast (Expr b) Coercion
| Tick (Tickish Id) (Expr b)
| Type Type
type Arg b = Expr b
type Alt b = (AltCon, [b], Expr b)
data AltCon = DataAlt DataCon | LitAlt Literal | DEFAULT
data Bind b = NonRec b (Expr b) | Rec [(b, (Expr b))]
No built-in functions necessary
for expressing standard logical functions
(Equality, Arithmetic, Booleans ... )
We add some builtins anyway, for good integration into ASP
and ability to refer to non-defined data
& | SetRef | String -> Int -> Set |
|| | Filter | Set -> (Dom -> Bool) -> Set |
. | Member | Set -> Dom -> Bool |
@ | AsFunc | Set -> Dom -> Dom |
+*-/ | Arithmetic | Dom -> Dom |
= | Equality | Dom -> Dom -> Bool |
# | Herbrand | String -> Dom (interpret string as herbrand functor) |
? | Empty | Set -> Bool (True iff the set is empty) |
? (|| p1 (\x -> not(. q1 x)) )
Theory: expression which needs to evaluate to true
Add 1 constraint to ASP
:- result(false).