$Id: Domains.lhs,v 1.4 1999/10/07 14:30:36 leavens Exp $

Semantic domains for the core language of
David A. Schmidt's "The Structure of Typed Programming Languages"
(MIT Press, 1994).

AUTHOR: Gary T. Leavens.

> module Domains where
> import qualified Stores

   SEMANTIC DOMAINS MODELED IN HASKELL

See Schmidt's figure 1.6 for the usual formatting.

The booleans

> type DBool = Bool
> true = True
> false = False

> -- Operations:
> -- not is already in Haskell
> equalbool :: (DBool, DBool) -> DBool
> equalbool(m, n) = (m == n)

Note that there are 3 DBool values: true, false, and bottom.
This is unavoidable when using a programming language,
but it is an approximation.


The integers

> type DInt = Integer

> -- Operations:
> plus :: (DInt,DInt) -> DInt
> plus(m,n) = m + n
> equalint :: (DInt,DInt) -> DBool
> equalint(m,n) = (m == n)


Locations

> type DLocation = Stores.Location

Stores

> type DStore = Stores.Store StorableValue

> lookupStore :: Stores.Storable storable =>
>    (DLocation, [storable]) -> storable
> lookupStore p = Stores.lookup $! p

> updateStore :: 
>   (DLocation, StorableValue, DStore) -> DStore
> updateStore t = Stores.update $! t

> emptyStore :: DStore
> emptyStore = Stores.emptyStore

> allocateStore :: DStore -> (DLocation, DStore)
> allocateStore ds = Stores.allocate $! ds


Storable Values

The type synonym StorableValue is intended to make reuse of this
module a bit easier.  In particular, if, for example, you need to
store Booleans, then you'll need to change this into a data definition.

> type StorableValue = DInt


The domain StorableValue is an instance of the class Storable,
defined in the Stores module.

> instance Stores.Storable Integer where
>   defaultContents = 0


Expressible Values

The meaning of an expession in a given store is an expressible value.
Expressible values are either integers or booleans.

> data ExpressibleValue = InInt DInt
>                       | InBool DBool
>                         deriving Eq

It's useful for ExpressibleValue to be an instance of the class Show,
for output of expression values.

> instance Show ExpressibleValue where
>   showsPrec p (InInt i) = showsPrec p i
>   showsPrec p (InBool b) = showsPrec p b
