Skip to content

Added Monte Carlo in Haskell #119

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 2 commits into from
Jun 16, 2018

Conversation

jiegillet
Copy link
Member

Monte Carlo in Haskell + a few typos in monte_carlo.md

@jiegillet jiegillet added Implementation This provides an implementation for an algorithm. (Code and maybe md files are edited.) Chapter Edit This changes the archive's chapters. (md files are edited.) labels Jun 3, 2018
@jiegillet jiegillet requested a review from leios June 3, 2018 12:54
@Butt4cak3
Copy link
Contributor

Do you use different editors for .md and .hs files? You removed some trailing whitespaces from the .md file, but your Haskell code has trailing whitespace in it. Just wondering how that happened.

@Gathros Gathros added Chapter Edit This changes the archive's chapters. (md files are edited.) and removed Chapter Edit This changes the archive's chapters. (md files are edited.) labels Jun 16, 2018
Copy link
Contributor

@Butt4cak3 Butt4cak3 left a comment

Choose a reason for hiding this comment

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

I'm not very fluent in Haskell, so I hesitated to create a review at first. Seeing that nobody else is willing to take on the job, I decided to do it anyway. I can't really say anything regarding style or good practices, but I could analyze the code and come to the conclusion that it is, in fact, correct.

I just have one question that I'd like you to answer for me before I merge your PR. It's not a change request, I'm just curious.

where makePairs = take n $ toPair (randomRs (0, 1) g :: [Float])
toPair (x:y:rest) = (x, y) : toPair rest
inCircle (x, y) = x^2 + y^2 < 1
count = (*4) . (/fromIntegral n) . fromIntegral . length
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks super backwards. Is it common to define functions in this way? As someone who doesn't know too much about Haskell, this would be much more intuitive:

        count l = fromIntegral (length l) / fromIntegral n * 4

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, you're right, I sometimes get carried away with point-free style (not writing the parameters explicitly), I usually like it better, but in this case your suggestion is much better.

Copy link
Contributor

Choose a reason for hiding this comment

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

If you want to change that line, go ahead and add another commit. If not, say the word and I'll merge.

@jiegillet
Copy link
Member Author

Thanks for the review. I did use different editors, I was teaching a class about vim at the time, so I used it to edit my code get warmed up. I'll review it.

@Butt4cak3 Butt4cak3 merged commit e0ece15 into algorithm-archivists:master Jun 16, 2018
@jiegillet jiegillet deleted the monteCarlo branch August 4, 2018 12:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Chapter Edit This changes the archive's chapters. (md files are edited.) Implementation This provides an implementation for an algorithm. (Code and maybe md files are edited.)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants