[clean-list] Is it possible to use Dynamics to do Multi-Stage Programming in Clean?

Arjen van Weelden A.vanWeelden at cs.ru.nl
Sat Jul 15 14:43:03 MEST 2006


Hi Alexsandro,

It's not clear to me why you keep wrapping dynamics in dynamics. You can
use pattern matching (on the value and the type) to extract the
expression. For instance:

Start :: Int
Start = c     // the answer would be 9
  where
    a = dynamic 1 + 2
    b = case a of (x :: Int) -> dynamic x * x
    c = execute b

execute :: Dynamic -> a | TC a
execute (x :: a) = x

I found the following definition: "Multi-stage programming (MSP) is a
paradigm for developing generic software that does not pay a runtime
penalty ...". I'm afraid that my answer has nothing to do with
'Multi-Stage Programming'. Using dynamics, you will always have a
run-time penalty. I looks like you need something like Template Haskell
or MetaOCaml.

kind regards,
	Arjen

Alexsandro Soares wrote:
> Hi all,
> 
>   I'm tryng to make a strongly-typed genetic
> programming system in Clean. I'm thinking in use the
> Dynamics feature to simulate multi-stage programming,
> but I'm not sure about this... 
>   What's wrong with the following code? How can I
> implement the "execute" function?
> 
> -------- Test.icl --------------------------
> module Test
> 
> import StdEnv
> import StdDynamic
> import StdDynamicFileIO
> 
> Start = c     // the answer would be 9
>   where
>     a = dynamic (1+2) // dynamically generates source
> code at runtime and delay its execution
>     b = dynamic (a * a) // combine the delayed values
> to construct larger ones
>     c = execute b       // compile and execute the
> dynamically generated code
> 
> ------------------------------
> 
>   Thanks in advance for any answer.
> 
>    Cheers,
>    Alex


More information about the clean-list mailing list