[Haskell-beginners] evaluation of expressions [was Re: eval command?]

Andrew Sackville-West andrew at swclan.homelinux.org
Tue Oct 28 20:20:12 EDT 2008

On Tue, Oct 28, 2008 at 07:00:00PM -0400, Tony Hannan wrote:
> On Mon, Oct 27, 2008 at 11:26 PM, Brandon S. Allbery KF8NH <
> allbery at ece.cmu.edu> wrote:
> > On 2008 Oct 27, at 23:25, Andrew Sackville-West wrote:
> >
> >> this raises a question for me, being a bit of a schemer. Is there any
> >> parallel in haskell to the data is code model of the lisp family? For
> >> example, playing around in scheme with a symbolic differentiator, it
> >> is trivial to then evaluate the differentiated s-expression at
> >> arbitrary value by representing the expression, and it's derivative as
> >> a regular scheme expression.
> >>
> >> Is this something that can be done in haskell? My initial impression
> >> is no, that you'd have to parse it as an expression and evaluate it as
> >> you would in regular imperative languages. I'd love to hear otherwise.
> >>
> >
> >
> > You get this in a type-safe form with Template Haskell; you can operate on
> > expressions at the AST level.
> >
> >
> Yeah, but can you do this at run time? I though Template Haskell can only be
> used at compile time.

That's what I'm talking about, run time evaluation of code/data. In
scheme, I can take as input

 (+ (exp x 2) (* 2 x)) 

a representation of x^2 + 2x

I can feed that "data" into a function

(derive input)

and get back 

(+ (* 2 x) 2)

a representation of 2x +2, the derivative of the above. The function
derive can manipulate that "Data" which is just a list, or
s-expression like any other data (for example accessing the first
element in the list, determining that it's a '+' and so calling derive
recursively on the two following elements).

then I can feed that result into (eval) with some information about
what the value of x is and it will be evaluated just like a regular
scheme expression. something like (it's been a while):

(let ((x 2))
     (eval default-environment (derive (input))))

where default-environment lets you get the information about the
current environment into the eval environment so that x has a
value. So now, what was "Data" a moment ago is treated as executable
within the eval.

The above (let) would spit out(in this case) a value of 6. 

Is such a thing possible in haskell?

(I'm really just curious, I have no need of this functionality at this
point). Oh, and I apologise for the fingernail clippings...


-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: Digital signature
Url : http://www.haskell.org/pipermail/beginners/attachments/20081028/90bb0d32/attachment-0001.bin

More information about the Beginners mailing list