liboleg-2010.1.10.0: An evolving collection of Oleg Kiselyov's Haskell modules

Lambda.Semantics

Synopsis

Documentation

data Entity Source

Here we encode the target language, the language to express denotations (or, meanings) Following Montague, our language for denotations is essentially Church's Simple Theory of Types also known as simply-typed lambda-calculus It is a form of a higher-order predicate logic.

Constructors

John 
Mary 

Instances

class Lambda lrepr whereSource

We define the grammar of the target language the same way we have defined the grammar for (source) fragment

Methods

john' :: lrepr EntitySource

mary' :: lrepr EntitySource

like' :: lrepr (Entity -> Entity -> Bool)Source

own' :: lrepr (Entity -> Entity -> Bool)Source

farmer' :: lrepr (Entity -> Bool)Source

donkey' :: lrepr (Entity -> Bool)Source

true :: lrepr BoolSource

neg :: lrepr Bool -> lrepr BoolSource

conj :: lrepr Bool -> lrepr Bool -> lrepr BoolSource

exists :: lrepr ((Entity -> Bool) -> Bool)Source

app :: lrepr (a -> b) -> lrepr a -> lrepr bSource

lam :: (lrepr a -> lrepr b) -> lrepr (a -> b)Source

Instances

Lambda C 
Lambda R 
Lambda lrepr => Lambda (P lrepr) 
States c => Lambda (D c) 

data R a Source

Syntactic sugar

The first interpretation: evaluating in the world with John, Mary, and Bool as truth values. Lambda functions are interpreted as Haskell functions and Lambda applications are interpreted as Haskell applications. The interpreter R is metacircular (and so, efficient).

Constructors

R 

Fields

unR :: a
 

Instances

Lambda R 
States R

We correspondingly extend our R, C, P intrepreters of Lambda

Show a => Show (R a) 

data C a Source

Running the examples

We now interpret Lambda terms as Strings, so we can show our formulas. Actually, not quite strings: we need a bit of _context_: the precedence and the number of variables already bound in the context. The latter number lets us generate unique variable names.

Constructors

C 

Fields

unC :: Int -> Int -> String
 

Instances

Lambda C 
Dynamics C 
States C 
Show (C a) 
Show (Sem (P C) a) 
Show (Sem C a) 
Show (Sem (D (P C)) S) 
Show (Sem (D C) S) 
Show (D (P C) Bool) 
Show (D C Bool) 
Show (Sem (P C) a) 
Show (Sem C a) 

type family Known lrepr a Source

We can now see the examples

The displayed difference between lsen4 and lsen4' shows that beta-redices have been reduced. NBE.

Normalizing the terms: performing the apparent redices

data P lrepr a Source

Constructors

P 

Fields

unP :: lrepr a
 
known :: Maybe (Known lrepr a)
 

Instances

Lambda lrepr => Lambda (P lrepr) 
Dynamics lrepr => Dynamics (P lrepr) 
States lrepr => States (P lrepr) 
Show (lrepr a) => Show (P lrepr a) 
Show (Sem (P C) a) 
Show (Sem (D (P C)) S) 
Show (D (P C) Bool) 
Show (Sem (P C) a)