Crypt Master cryptmaster at hotmail.com
Thu Jul 1 12:01:25 EDT 2004

```Hi

I consider myself a pretty good imperative programmer, been at it for
decades, and am tryibng my hand at Haskell now. Unfrituantly I am not
"getting" it all that quickly despite having the multimedia haskell book.

To start ghetting some hands on, I thought iI owuld do something which i
have done many times before in imperatives, a basic Genetic Algorithm
Library. Unfortunatly I am comming unstuck straight away and was hoping some
of you kind folk could point in the direction of dry land :-)

iIf your not familiar with GAs its not too important, simply a GA searches
over the whole solution space randomly. Well not quiet, its a guided search,
its guided by evolution ie by the fitness of each indicidual of a random
initial population. Evolution is simulated by 3 basic operators, selection,
cross over and mutation. selection is which indiviuals get to breed, cross
over is how they breed, and mutation is just things intetresting.

So after reading the multimedia book, Iimmediately thought of a defining the
solution space as a infinite list. I was hoping then I could do things like
take 5 gaSolutionSpace to get 5 iterations or generations. My first attempt
tied to use lis syntax [], but it wouldnt compile and after seeing
"numsFrom" ina  tutorial I redefined it as such. Here is what I have so far:

-- gaSolutionSpace :: [a] -> [a]
-- gaSolutionSpace [] = gaSolutionSpace createRandomPopulation -- recursive
base case
gaSolutionSpace x = x : gaSolutionSpace (evolvepopulation x)

evolvepopulation :: a -> a
evolvepopulation p = mutate cross select p

-- createRandomPopulation :: [Num a]
createRandomPopulation = [1,23,4,5,6]

cross p  = p
mutate p = p
select p = p

----
The take operator doesnt work on this. from hugs:

HAGA> take 5 gaSolutionSpace [1,2,3,4,5]
ERROR - Type error in application
*** Expression     : take 5 gaSolutionSpace [1,2,3,4,5]
*** Term           : take
*** Type           : Int -> [e] -> [e]
*** Does not match : a -> b -> c -> d

I am not sure I follow this. I assume its cause I didnt use the list
notation in definaing gaSolutionSpace. Any ideas on how to do that. ? What
about using map. It occurs to me that you can define gaSolutionspace as a
map of the evolvolepopuloation function acrossan infinite solution space,
but I dont know how to makethis  infinte list to map over ...?

There ar 2 papaers on GAs in haskell, but they use monads. I realise for
performance I will probably have to use them too, but for now I would liek
to do it without mondas even if performance isnt optimal.

Sorry again for the newbie questions, but any help is appreciated.

Stephen

_________________________________________________________________
Help STOP SPAM with the new MSN 8 and get 2 months FREE*
http://join.msn.com/?page=features/junkmail

```