Thank You Ben,

Your solution is really neat. I was trying to create the infix 'eat' function when I was thinking of implementing this in Haskell. But I completely forgot about being able to use the Record syntax to do this.

I am not sure about the purpose of !Int, but that is something for me to read more and learn :)

Thank You,
Elric

 On 06/08/2014 04:52 PM, Ben Gamari wrote:
Elric <elric@kiosa.org> writes:

Hi,

Disclaimer: I have been learning Haskell for a month and there are still 
several things about this wonderful language I know nothing of, so 
please bear with me. Also, I apologize for this (somewhat) long mail./

...
Below are the two versions of the code I came up with to solve this. 
Neither of them converge to the 'endStates' even after about 15 minutes. 
So there is definitely something wrong with what I have done. But after 
banging my head on the keyboard for more then a day with this, I would 
appreciate some pointers or help.

For one, you don't appear to be removing duplicates from the search set
resulting in a blow-up in your search space.

I thought using the ADT was causing the performance issue and reverted 
to using a plain 3-termed list which holds [Lion count, Wolf Count, 
Sheep Count] :: [Int]

Your problem here isn't the use of ADTs, it's the use of lists. Why not
instead define a forest as follows?

    data Forest = Forest { wolfs, lions, goats :: !Int }

Note how I used a strictness annotation !Int here to ensure that the
compiler unboxes these members (at least with GHC >= 7.8), which is
almost certainly what you want in this case.

Anyways, I took a quick stab at the problem myself. My approach can be
found here[1]. Performance isn't great (a bit better than Javascript)
but then again the code is pretty much as naive as one could get. I'm
sure things could be improved.

Cheers,

- Ben


[1] https://gist.github.com/anonymous/e4a2ccd8df05255d5ed5