
Hi Thanks for responding and taking the time to respond so fully. Its much appreciated!
From what I can see, a key difficulty you're having is with the "evolvepopulation" function. You've given it the type a -> a, which pretty much requires it to be an identity function, because it's not allowed to make any assumptions about the values it takes.
I was going trying for generic as possible, I am keen to expore how much more expressive one can be in functional lanaguages.
To make things easier to read, try defining types for Population and Individual (they can always be generalized later).
type Individual = Int type Population = [Individual]
A use fill tip, thanks. [Snip]
It looks like you're defining evolution as the composition of mutate, cross, and select, but got tripped up by the order of evaluation. Specifically, "mutate cross select p" is the same as "((mutate cross) select) p", which probably isn't what you want.
It only recently dawned on me that functions are left asscoaitive and your absolutly right its not what i had in mind.
If you have: mutate :: Population -> Population cross :: Population -> Population select :: Population -> Population
Then you could define evolve p = mutate (cross (select p))
-- alternative: -- evolve = mutate . cross . select
I now get what the f.g is as well :-) Thanks, the alternate format with the original has just clicked something else into place.
Starting from an initial population, you want to generate a sequence by iterating evolve, starting from an initial population. Haskell provides a function "iterate" for this purpose, or you can define your own.
Yeah other posters suggested this as well. I now have the the same function as you mentioned which is very nice: gaSolutionSpaceFrom :: a -> [a] gaSolutionSpaceFrom = iterate evolvePopulation [snip]
I found it helpful to remember that you can think of a function f :: a -> b -> c as taking two arguments of types a and b and returning a result c, or as taking a single argument of type a and returning a result of type b -> c. Once you become comfortable with partial application, a lot of Haskell code starts to make more sense.
I understood the partial application when explained in simple terms, but I
find I have a hard time when it used in more coimplicated examples. The
currying in the "The Haskell School of Expression" left with a big "Huh",
even though a simple application makes sense to me.
"The craft of Functional Programming" it seesm thicker more methdoical, so I
may get some more of the basics down in the next few weeks.
Thanks again.
------------------------------
Message: 8
Date: Sat, 03 Jul 2004 08:38:55 +0000
From: "Crypt Master"
-- gaSolutionSpace :: [a] -> [a]
gaSolutionSpace x = x : gaSolutionSpace (evolvepopulation x)
-Stop deceiving yourself until it's too late. -Why did you comment out the type annotation? *Sheepish Grin* its historical, my original thought and attempt was that you would recieve a list of populations and evolve it to a bigger list of populations. Hence the [a] -> [a]. It didnt work out too well as this is what I came up with: gaSolSpace [x:xs] = gaSolutionSpace [x : evolePopulation x] Eventually i realised that I needed to evolve a single population, not a list, which let to a -> [a] and thanks to Keith I now have this: gaSolutionSpaceFrom :: a -> [a] gaSolutionSpaceFrom = iterate evolvePopulation Thanks _________________________________________________________________ Add photos to your e-mail with MSN 8. Get 2 months FREE*. http://join.msn.com/?page=features/featuredemail ------------------------------ _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe End of Haskell-Cafe Digest, Vol 11, Issue 3 ******************************************* _________________________________________________________________ Help STOP SPAM with the new MSN 8 and get 2 months FREE* http://join.msn.com/?page=features/junkmail