[Haskell] Running haskell from within Haskell

Nick Benton nick at microsoft.com
Wed Jan 19 04:27:34 EST 2005


I have a forthcoming expository JFP paper on one way to do what I think
you're asking for without any extra-language hackery:

Embedded Interpreters

This is a tutorial on using type-indexed embedding/projection pairs when
writing interpreters in statically-typed functional languages. The
method allows (higher-order) values in the interpreting language to be
embedded in the interpreted language and values from the interpreted
language may be projected back into the interpreting one. This is
particularly useful when adding command-line interfaces or scripting
languages to applications written in functional languages.

We first describe the basic idea and show how it may be extended to
languages with recursive types and applied to elementary
meta-programming. We then show how the method combines with Filinski's
continuation-based monadic reflection operations to define an
`extensional' version of the call-by-value monadic translation and hence
to allow values to be mapped bidirectionally between the levels of an
interpreter for a functional language parameterized by an arbitrary
monad. Finally, we show how SML functions may be embedded into, and
projected from, an interpreter for an asynchronous \picalc\ via an
`extensional' variant of a standard translation from $\lambda$ into
$\pi$.

There's a preprint available on my web page at
http://research.microsoft.com/~nick/publications.htm

The code is in SML, but the basic idea works just the same in Haskell
(in fact, you can use type classes to make it look even slicker). 

  Nick

-----Original Message-----
From: haskell-bounces at haskell.org [mailto:haskell-bounces at haskell.org]
On Behalf Of Donald Bruce Stewart
Sent: 19 January 2005 02:51
To: Vivian McPhail
Cc: haskell at haskell.org
Subject: Re: [Haskell] Running haskell from within Haskell

vivian.mcphail:
> 
>    Dear All,
>    I have a parser which has entries for each word, such as:
> 
>    ate  = s \ np / np  : ^x y.did(eat y x);
> 
>    so each word has a type (s \ np / np) and a semantics (the
>    lambda term ^x y.did(eat y x)).
> 
>    Currently I parse the semantics into lambda terms and use my
>    own lambda-interpreter to do evaluation.
> 
>    "I ate a python programmer" would be evaluated as:
> 
>    did(eat I (a python programmer))
> 
>    What I would like to be able to do is actually use haskell
>    functions in the semantic slot for each word.  This requires
>    parsing a fragment of a file into haskell and then making it
>    available as code within my program.
> 
>    Is this possible?
> 
>    for example:
> 
>    kicked = s \ np / np : \x y -> case x of
> 
>                                        (the bucket) = did(die
>    y)
> 
>                                        _                = did(k
>    ick y x);
> 
>    Thanks in advance.

You may be able to use the eval functions provided by hs-plugins
    http://www.cse.unsw.edu.au/~dons/hs-plugins/

A number of mini-edsl-interpreters for Haskell have been written this
way. Where:
    eval :: Typeable a => String -> [Import] -> IO (Maybe a)

An example of an interpreter for Haskell, using this mechanism, is at:
 
http://www.cse.unsw.edu.au/~dons/hs-plugins/hs-plugins-Z-H-14.html#node_
chap_B

-- Don
_______________________________________________
Haskell mailing list
Haskell at haskell.org
http://www.haskell.org/mailman/listinfo/haskell


More information about the Haskell mailing list