[clean-list] Is it possible to use Dynamics to do Multi-Stage
Programming in Clean?
Arjen van Weelden
A.vanWeelden at cs.ru.nl
Sun Jul 16 10:22:45 MEST 2006
Hi Alex,
This is possible in Clean, but you'll have to use dynamics is a
different way than in your example. Dynamics don't generate code, only
the Clean compiler does. For each solution, let your program create a
Clean source file with the following content:
import StdDynamicFileIO
Start world
= writeDynamic "solution_i" (dynamic solution_i :: Solution) world
Compile all those files with the Clean compiler and execute them (in the
same way as one executes the Clean compiler, using the CreateProcess
Windows API call). Now, your program can read all those dynamics, and
all generated code will be linked in automatically.
regards,
Arjen
Alexsandro Soares wrote:
> Hi Arjen,
>
> Thank you for your answer.
> I don't about your previous knowledgement about
> genetic programming (GP), so I'll describe it to you.
> GP is a kind of genetic algorithm that try solve
> problems using Darwinian evolution theory. In GP
> exists a population of candidate solutions, each
> solution is represented by a program. These programs
> will be combined and transformed using genetic
> operators like crossover, mutation, etc. You can see
> each solution as a little program implemented in a DSL
> specified by the user.
> Each solution must be executed and its result
> compared with an output expected. One way of
> performing this step it is to create an interpreter
> to DSL (the standard GP algorithm uses it), but this
> is slow, because one can have millions of such
> programs to execute. I'm trying to figure out how to
> use Clean Compiler to generate code at run-time to
> these DSLs.
> So, I ask you: Is it possible in Clean? If the
> answer is yes, can you send me a little example?
>
> Cheers,
> Alex
>
> --- Arjen van Weelden <A.vanWeelden at cs.ru.nl>
> escreveu:
>
>> 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