[Haskell-cafe] Re: pointers for EDSL design

John Lato jwlato at gmail.com
Mon Oct 11 05:42:02 EDT 2010

On Fri, Oct 8, 2010 at 10:29 PM, <oleg at okmij.org> wrote:

> John Lato wrote:
> > So here's a very simple expression:
> >
> > t1 = let v = sigGen (cnst 1) in outs v v
> >
> > which is what led to my question.  I'm binding the sigGen to 'v' to
> > introduce sharing at the meta-level.  Would it be better to introduce
> > support for this in the dsl?
> Often this is not a question of preference but that of
> necessity. Sharing at the meta-level may help the generator, but it
> does _not_ translate into the sharing at the object level. In the
> generated code, the code for 'sigGen (cnst 1)' shall be
> duplicated. It could be that two csound blocks must share the same
> signal source, to receive samples in parallel. Meta-level sharing
> (Haskell's let) would not do. We need a construct for an object-level
> let, for example

This was a problem, but I did arrive at a solution.  When my interpreter
evaluates an expression, it creates a named variable to store the result and
memoizes it.  Future evaluations of the expression with the same arguments
become a reference to the named variable.

This works well for functions.  However, there may be some operations that
should not be memoized.  These can be handled by simply having the
interpreter re-evaluate the expression.  I've found that including a
user-supplied label to control memoization creates consistency within the
embedded language, and thus a more natural programming style.

When targeting csound, the generated code is nearly exactly what I would
have written directly, except for auto-generated variable names.  I don't
yet know how feasible it will be for other interpreters though.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20101011/4c290850/attachment.html

More information about the Haskell-Cafe mailing list