[e-lang] E-on-Haskell

Kevin Reid kpreid at mac.com
Tue Jun 27 21:09:02 EDT 2006

The E implementation in Haskell I've been playing with recently is  
now in my Subversion repository, including most of the development  


For those who haven't heard of it before, this E implementation is  
intended primarily for demonstration of an explicit implementation of  
E semantics, not efficiency or practicality. Therefore, it does not  
at the moment implement the E language; just the 'ELib' portion.

It contains some documentation, and I've tried (and mostly failed) to  
keep it readable by non-Haskell programmers.

It does not yet implement ejectors.

If you'd like further explanation of the code, feel free to ask me on  
e-lang or on IRC at irc.freenode.net #erights.

To run E-on-Haskell, install GHC <http://www.haskell.org/ghc/>, then do:

$ ghci
Prelude> :load e.lhs
Ok, modules loaded: E.

The GHCi REPL now lets you use all definitions in the E module.

*E> testAll

testAll runs all the built-in tests; each "Nothing" indicates a  
passed test.

To run an E-style computation, you must use 'runExec' to set up a  
vat. However, this defeats GHCi's guessing of whether you want the  
result, so you have to explicitly print it.

*E> do { result <- runExec (call (ref (1::Integer)) "add" [ref  
(1::Integer)]); print result }
ref 2

Short introduction to the complications of this code:

The '::Integer' type annotations are necessary because in Haskell,  
numeric literals may be of any numeric type, and since 'ref' accepts  
many types we must pick one explicitly.

'ref' is a function which converts an arbitrary Haskell value (whose  
behavior-as-an-E-ref has been defined) into a value of type AnyRef,  
which allows only Ref operations, so that the type system lets us mix  
them arbitrarily.

*E> :info ref
ref :: Ref a => a -> AnyRef     -- Defined at e.lhs:146:1

'Ref' is a type-class, which is like an interface in Java. The type  
of 'ref' means that it accepts a value of any type which is an  
instance of Ref ('implements Ref' in Java) and returns a value of  
type AnyRef.

*E> :info Ref
class (Typeable r, Show r) => Ref r where
   state :: r -> Exec RefState
   call :: r -> Verb -> Args -> Result
   send :: r -> Verb -> Args -> Result
   refCast :: Typeable a => r -> Exec (Maybe a)
   observableTypeOf :: r -> Exec (Maybe TypeRep)
   shallowIdentity :: r -> Exec ShallowIdentity
   approved :: AnyRef -> r -> Exec Bool
         -- Defined at e.lhs:89:31
instance Ref AnyRef     -- Defined at e.lhs:134:1
instance Ref ()         -- Defined at e.lhs:227:1
instance Ref Char       -- Defined at e.lhs:229:1
instance Ref String     -- Defined at e.lhs:231:1
instance Ref Double     -- Defined at e.lhs:233:1
instance Ref Bool       -- Defined at e.lhs:235:1
instance Ref a => Ref (Maybe a)         -- Defined at e.lhs:237:1
instance Ref Integer    -- Defined at e.lhs:239:1
instance Ref a => Ref [a]       -- Defined at e.lhs:246:1
instance Ref (VarSlot AnyRef)   -- Defined at e.lhs:261:1
instance Ref ELambda    -- Defined at e.lhs:279:1
instance Ref Promise    -- Defined at e.lhs:335:1
instance Ref Resolver   -- Defined at e.lhs:355:1
instance Ref Buffer     -- Defined at e.lhs:453:1
instance Ref TurnQueue  -- Defined at e.lhs:478:1

Kevin Reid                            <http://homepage.mac.com/kpreid/>

More information about the e-lang mailing list