Skip to content

[Haskell] Barnsley Fern #851

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 21, 2021

Conversation

jiegillet
Copy link
Member

Seeing as #704 was reviewed recently, I'm pushing forward with Barnsley Fern.

I also fixed a typo in the chapter: 022 -> 0.22.

Output for 100k points:
Screen Shot 2021-08-30 at 12 31 21

@jiegillet jiegillet added the lang: haskell Haskell programming language label Aug 30, 2021
@Amaras Amaras added the Implementation This provides an implementation for an algorithm. (Code and maybe md files are edited.) label Aug 31, 2021
@jiegillet jiegillet requested review from leios and removed request for leios September 10, 2021 00:24
to_choice x = (+ 1) $ length $ takeWhile (x >) cumulProbabilities

points = Point x y : zipWith (hutchinson !) (map to_choice picks) points

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{-

Here is alternative code with IO monad instead of explicit Random Generator.
You do random generation in sequence anyway (through g, g' and g''),
so why not let IO monad care about the sequential stuff for you?
Then you won't even need newStdGen in main function, you work in IO already.

(This is the code without taking into account my other comments)


chaosGame :: Int -> [Double] -> Array Int (Point -> Point) -> IO [Point]
chaosGame n probabilities hutchinson = do
x <- randomIO
y <- randomIO

picks <- replicateM n $ randomRIO (0, 1)
let cumulProbabilities = scanl1 (+) probabilities
to_choice x = (+ 1) $ length $ takeWhile (x >) cumulProbabilities

points = Point x y : zipWith (hutchinson !) (map to_choice picks) points
return points
-}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I usually try to stay away from IO until the very end. I feel code is more portable when it's pure. Yes, it's true that I'm doing IO in the end, but I want to focus more on the algorithm, and less on the task...

@leios
Copy link
Member

leios commented Nov 3, 2021

What do you think? Is this close to mergable?

@jiegillet
Copy link
Member Author

@leios I probed Seva a couple of times, but I guess he was too busy to check. He told before me that the initial code was already fine, and I've integrated all of his suggestions but one (with a valid reason) so I think this can be approved and merged, honestly. By you probably :)
Sorry, looks like all the Haskell PRs are irregular somehow.

@leios
Copy link
Member

leios commented Nov 21, 2021

Ok, I thought that was what happened. Happy to merge it then!

@leios leios merged commit 41a1728 into algorithm-archivists:master Nov 21, 2021
@jiegillet jiegillet deleted the haskell-barnsley branch November 21, 2021 14:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Implementation This provides an implementation for an algorithm. (Code and maybe md files are edited.) lang: haskell Haskell programming language
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants