Skip to content

add ocaml to euclidean #11

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 1 commit into from
Sep 17, 2017
Merged

add ocaml to euclidean #11

merged 1 commit into from
Sep 17, 2017

Conversation

strega-nil
Copy link

No description provided.

@leios
Copy link
Member

leios commented Sep 17, 2017

Well, that's a language that isn't seen very often! Thanks for the submission! =)

@leios leios merged commit 940ebe0 into algorithm-archivists:master Sep 17, 2017
Copy link

@yawaramin yawaramin left a comment

Choose a reason for hiding this comment

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

A bit late but hopefully helpful.

### OCaml

```ocaml
let rec euclid_mod a b =

Choose a reason for hiding this comment

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

Can also be written as

let rec euclid_mod a = function
  | 0 -> a
  | b -> euclid_mod b (a mod b)

This also looks more like the Haskell version that uses patterns directly in equations.

else
euclid_mod b (a mod b)

let rec euclid_sub a b =

Choose a reason for hiding this comment

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

Looks good, I'd condense it a little bit since the body is so narrow:

let rec euclid_sub a b =
  if a = b then a
  else if a < b then euclid_sub a (b - a)
  else euclid_sub (a - b) b


let chk1 = euclid_mod (64 * 67) (64 * 81)
let chk2 = euclid_sub (128 * 12) (128 * 77)
let () = print_string ((int_of_string chk1) ^ "\n")

Choose a reason for hiding this comment

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

Can use print_endline to avoid manually adding newlines, use pipe-forward, and also sequence into a single expression, i.e.

let () =
  chk1 |> int_of_string |> print_endline;
  chk2 |> int_of_string |> print_endline

@strega-nil strega-nil deleted the add-ocaml branch February 16, 2018 03:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants