211
I love Rust (lemmy.blahaj.zone)
you are viewing a single comment's thread
view the rest of the comments
[-] BaumGeist@lemmy.ml 17 points 2 days ago* (last edited 2 days ago)

Implementing Equality in Haskell:

    deriving (Eq, Ord)

After learning how easy it was to implement functional programming in Rust (it's almost like the language requires it sometimes), I decided to go back and learn the one I had heard about the most.

It opened my mind. Rust takes so many cues from Haskell, I don't even know where to begin. Strong typing, immutable primitives, derived types, Sum types. Iterating and iterables, closures, and pattern matching are big in Haskell.

I'm not saying Rust uses these because Graydon Hoare wanted a more C-like Haskell, but it is clear it took a lot of elements from the functional paradigm, and the implementations the designers were familiar with had descended through Haskell at some point.

Also, deriving is not the same as implementing. One is letting the compiler make an educated guess about what you want to compare, the other is telling it specifically what you want to compare. You're making, coincidentally, a bad comparison.

[-] Ephera@lemmy.ml 9 points 1 day ago

The first iteration of the Rust compiler was written in OCaml...

[-] expr@programming.dev 5 points 2 days ago

Don't need the Ord instance for equality, just Eq is sufficient. Ord is for inequalities.

The point of the post is that most mainstream languages don't provide a way to automatically derive point-wise equality by value, even though it's pervasively used everywhere. They instead need IDEs to generate the boilerplate rather than the compiler handling it.

this post was submitted on 15 Nov 2024
211 points (94.1% liked)

Programmer Humor

32483 readers
429 users here now

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

founded 5 years ago
MODERATORS