Skip to content
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

[sfh][2023] Day 1 (OCaml/Reason) #120

Merged
merged 1 commit into from
Dec 2, 2023
Merged

[sfh][2023] Day 1 (OCaml/Reason) #120

merged 1 commit into from
Dec 2, 2023

Conversation

solomonhawk
Copy link
Contributor

@solomonhawk solomonhawk commented Dec 1, 2023

⚠️ Day 1 Spoilers ⚠️

https://adventofcode.com/2023/day/1

Disclaimer: I absolutely made a complete mess of things here I'm sure. I don't know anything about writing idiomatic/elegant OCaml/Reason.

It feels like they wanted to be extra tricky because they did not explain a key edge case that should be accounted for in solutions.

This diff is a bit noisy since it has all the (one-time) env setup stuff along with the Day 1 solution. Click here if you just want to see the Day 1 solution.

Thoughts

  • ocaml ecosystem is a bit hard to navigate, not very beginner friendly (have to know which stdlib modules to avoid, which stdlib userland package to pull in, debug issues with extensions by pulling in arcane modules, figure out printing - and as a result dive into derived behaviors)
  • love pattern matching
  • love pipes
  • recursion is recursion

Takeaways

  • From what I can tell, the OCaml stdlib isn't designed to be a fully-featured user-facing library, instead it primarily serves the needs of the ocaml compiler. Instead we have various packages to pick from that provide different bundles of standard behavior e.g. Base, Core, Containers, and Batteries
  • I still don't fully know what I'm doing with regards to extensions which are the thing that provides additional language syntax and behavior (inline tests, etc.). I had to make sure I opend some libraries related to sexpr's to get rid of Unbound module <x> errors in inline tests. This felt confusing, but is mostly just due to lack of familiarity/understanding.
  • Reason is extra confusing because it's conflated with ReasonML/ReScript and there's a whole history behind e.g. bucklescript and all the JS interop stuff.
  • Tooling is weird. I think I probably should have just used opam instead of esy as a package manager, but esy grants better sandboxing than raw opam switches and access to packages published on npm among other things

Copy link
Contributor

Choose a reason for hiding this comment

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

Are these esy.lock/ meant to be committed?

Copy link
Contributor Author

@solomonhawk solomonhawk Dec 1, 2023

Choose a reason for hiding this comment

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

My understanding is that they should be committed (like package-lock.json, but more verbose). The docs on esy.sh mention it here. Also, this starter repo doesn't omit them.

@solomonhawk solomonhawk merged commit 9a43ba0 into main Dec 2, 2023
2 checks passed
Comment on lines +22 to +36
let parse = (input: string): t => {
input
|> String.trim
|> String.split_on_char('\n')
|> List.map(line =>
line
|> String.to_list
|> List.map(char =>
switch (char) {
| '0' .. '9' => N(Char.to_int(char) - Char.to_int('0'))
| _ => L(char)
}
)
);
};
Copy link
Contributor

Choose a reason for hiding this comment

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

love2pipe 👏

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.

3 participants