[Haskell-cafe] A question on DSL's

Tom Hawkins tomahawkins at gmail.com
Mon Jan 4 18:14:27 EST 2010


On Mon, Jan 4, 2010 at 9:41 PM, Luke Palmer <lrpalmer at gmail.com> wrote:
> On Mon, Jan 4, 2010 at 12:16 PM, Tom Hawkins <tomahawkins at gmail.com> wrote:
>> One argument for option 2 is to carry forward datatypes to the target
>> language.  For example, if you want to describe a state machine with
>> the state as a type:
>
> What do you mean "carry forward".  Can you elaborate on your simple
> example?  What about it requires option 2?

Well in the case of Atom, it would be very convenient to write code like this:

data StopLight = Red | Yellow | Green

changeLight :: V StopLight -> Atom ()
changeLight light = light <== light'
  where
  light' = case value light of
    Red -> Green
    Yellow -> Red
    Green -> Yellow

The problem is the case expression is evaluated at compile-time, when
what we really want is to "carry forward" the case expression to the
run-time environment (aka. the generated code).  This example
illustrates the use of a simple enumerated type.  But full-blown
algebraic data types would also be useful in the run-time.  For
example, a Maybe type could be used to represent a valid signal: Just
validValue or Nothing if the signal is invalid.

Of course this is not a limitation if the run-time and compile-time is
the same environment, i.e. Haskell.  However, if the target is a
different language, such as C in the case of Atom, then the full power
of algebraic data types are lost with light embedded domain specific
languages.


More information about the Haskell-Cafe mailing list