-
-
Notifications
You must be signed in to change notification settings - Fork 359
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
Conversation
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. |
There was a problem hiding this 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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
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. |
Monte Carlo in Haskell + a few typos in monte_carlo.md