LambdASP

Untyped Lambda Calculus (ULC)

Expr = Variable
     | Expr Expr        (application)
     | λ Variable Expr  (abstraction)

Syntax

Reduction

(\lambda x. y) s \rightarrow y[x.=s]
(λx.y)sy[x.=s](\lambda x. y) s \rightarrow y[x.=s]

beta reduction (under capture avoidance)

Untyped Lambda Calculus (ULC)

Beta Normal Form

An expression where no beta-reduction is possible.

An expression has at most 1 beta normal form. 

(So it is independent of reduction strategy)

Uniqueness

ULC + Values

Expr = Variable
     | Expr Expr        (application)
     | λ Variable Expr  (abstraction)
     | Value            (domain elements)

Syntax

\Downarrow \text{reduces to}
reduces to\Downarrow \text{reduces to}

Naming Convention:

Uppercased constructors

Lowercased variables

(\x -> Pair x x) 7
Pair 7 7

Problem: No way to talk about real values

Example

ULC + V + Pattern Matching

Expr = Variable
     | Expr Expr        (application)
     | λ Variable Expr  (abstraction)
     | Value            (domain elements)
     | case Expr [(Pattern,Expr)] (pattern match)

Syntax

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)

ULC + V + Pattern Matching

\Downarrow \text{reduces to}
reduces to\Downarrow \text{reduces to}
\x -> (case x of (Pair y z -> y) ; _ -> x) (Pair 1 2)
1

Example

ULC + V + PM + Let Expression

Expr = Variable
     | Expr Expr        (application)
     | λ Variable Expr  (abstraction)
     | Value            (domain elements)
     | case Expr [(Pattern,Expr)] (pattern match)
     | let Variable Expr Expr

Syntax

Problem: No way to reuse values

Pattern = Variable      (bring variable into scope)
     | Value [Pattern]  (Constructor)
     | _                (don't care, universal match)

ULC + V + PM + Let Expression

let ifThenElse = (\x y z -> case x of 
            True -> y
            False -> z
) in

ifThenElse (jarig Jan) "hoera" "hallo"

Example

ULC + V + PM + Let Expression

let ifThenElse = (\x y z -> case x of 
            True -> y
            False -> z
) in

ifThenElse (jarig Jan) "hoera" "hallo"

Example

Translation into ASP

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))]

ULC(.) + Builtins

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

ULC(.) + Builtins

& 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)) )

ULC(.)

Theory: expression which needs to evaluate to true

Add 1 constraint to ASP

:- result(false).

ULC(.) + Builtins

LambdASP

By Ingmar Dasseville