[Haskell-cafe] Newbie questions

Crypt Master cryptmaster at hotmail.com
Sat Jul 3 05:07:05 EDT 2004


Thanks for responding and taking the time to respond so fully. Its much 

 >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.


>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


>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" <cryptmaster at hotmail.com>
Subject: Re: [Haskell-cafe] Newbie questions
To: duncan.coutts at worcester.oxford.ac.uk
Cc: haskell-cafe at haskell.org
Message-ID: <BAY18-F13KHmj9n1xxW00056ac5 at hotmail.com>
Content-Type: text/plain; format=flowed


People say function application in Haskell is written without brackets
but this can be misleading, here you do need brackets to indicate that
'gaSolutionSpace [1,2,3,4,5]' is one argument and not two. So you should
take 5 (gaSolutionSpace [1,2,3,4,5])


Thanks alot, this was very helpfull. It also makes more sense now that I
looked up the associativity of functions and found it to be left assoc. For
some reason I assumed it would automaically bracket form the right as such
(take (5 (gaSolutionSpace [1,2,3,4,5])))

but its actually this
(((take 5) gaSolutionSpace) [1,2,3,4,5])

Thanks again.

Tired of spam? Get advanced junk mail protection with MSN 8.


Message: 9
Date: Sat, 03 Jul 2004 08:46:24 +0000
From: "Crypt Master" <cryptmaster at hotmail.com>
Subject: [Haskell-cafe] Re: Newbie questions
To: wferi at afavant.elte.hu
Cc: haskell-cafe at haskell.org
Message-ID: <BAY18-F16gyf2M0KFHR000262c6 at hotmail.com>
Content-Type: text/plain; format=flowed

 >-- 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


Add photos to your e-mail with MSN 8. Get 2 months FREE*.


Haskell-Cafe mailing list
Haskell-Cafe at haskell.org

End of Haskell-Cafe Digest, Vol 11, Issue 3

Help STOP SPAM with the new MSN 8 and get 2 months FREE*  

More information about the Haskell-Cafe mailing list