OCaml: a Rust developer's first impressions
pthorpe92.github.io
OCaml: a Rust developer's first impressions
1–10 of 157 posts
Re: OCaml: a Rust developer's first impressions
#2Also, if you don't like the OCaml syntax, check out ReasonML, which is an alternative OCaml syntax that Facebook developed several years ago. It has the Algol-style that many modern languages today use.
Re: OCaml: a Rust developer's first impressions
#3Re: OCaml: a Rust developer's first impressions
#4OCaml is great, we learned it in class back in college, then we learned Rust right afterwards. Oftentimes people say OCaml is Rust without the borrow checker (or that Rust is OCaml with a borrow checker), but that's not quite true. Since it is entirely functional and recursive, it takes more time to wrap your head around. Now with OCaml 5, we also have algebraic effect support, something that Rust is looking to add i…
Re: OCaml: a Rust developer's first impressions
#5OCaml is great, we learned it in class back in college, then we learned Rust right afterwards. Oftentimes people say OCaml is Rust without the borrow checker (or that Rust is OCaml with a borrow checker), but that's not quite true. Since it is entirely functional and recursive, it takes more time to wrap your head around. Now with OCaml 5, we also have algebraic effect support, something that Rust is looking to add i…
I think about it the other way; Rust is an ML with a borrow checker. Most of the stuff I hear people gushing about in Rust is IMO them experiencing what's it's like to write ML.
Re: OCaml: a Rust developer's first impressions
#6Earlier quoted context omitted.
I think about it the other way; Rust is an ML with a borrow checker. Most of the stuff I hear people gushing about in Rust is IMO them experiencing what's it's like to write ML.
Yes and no, Rust is ML inspired but it is still way too imperative and not as functional to be called a true ML. But yes, things like Result and Option types, do-notion via "?," at least for Results and Options, algebraic data types are all part of the appeal. There sadly are still no higher kinded types though, but that is a difficult problem to solve and most won't encounter such problems anyway in day-to-day codin…
As a Haskell fanboy, this is how I feel about Ocaml and F#.
Re: OCaml: a Rust developer's first impressions
#7Earlier quoted context omitted.
Yes and no, Rust is ML inspired but it is still way too imperative and not as functional to be called a true ML. But yes, things like Result and Option types, do-notion via "?," at least for Results and Options, algebraic data types are all part of the appeal. There sadly are still no higher kinded types though, but that is a difficult problem to solve and most won't encounter such problems anyway in day-to-day codin…
> still way too imperative and not as functional to be called a true ML As a Haskell fanboy, this is how I feel about Ocaml and F#.
Re: OCaml: a Rust developer's first impressions
#8Yeah my semi-hot take is that type annotations in functions is a feature not a bug. It forces legible interfaces (with the exception of nasty generics I suppose).
Re: OCaml: a Rust developer's first impressions
#9at some point i got sick of trying to debug mysterious compile errors about types in ocaml and started declaring types for all of my function arguments; ocaml lets you do that. an example is http://canonical.org/~kragen/sw/dev3/mukanren.ml (an implementation of a tiny logic programming language, sort of like prolog with superpowers; cw inappropriate intimacy) where, for example, instead of writing
let rec disj g1 g2 t = mplus (g1 t) (g2 t)
i write let rec
disj (g1 : goal) (g2 : goal) (t : state) = mplus (g1 t) (g2 t)
which is more code, to be sure, but i think easier to understand because it's more explicit. and the compiler doesn't report your type errors in the wrong function anymore when you do thatif you aren't sure what the types should be (easy when parametric polymorphism gets involved) you can paste the code without type declarations into the repl and see what it says
in this case that looks like this
# let rec disj g1 g2 t = mplus (g1 t) (g2 t) ;;
val disj : ('a -> 'b stream) -> ('a -> 'b stream) -> 'a -> 'b stream =
and in fact my `goal` type is more specific, `state -> state stream`, thus favoring comprehensibility a bit over flexibility (i can always go back and generalize the type more later)this makes the code a bit more verbose but most functions are more than five words long so it's not actually that bad
maybe i should declare the return type too
let rec
disj (g1 : goal) (g2 : goal) (t : state) : state stream = mplus (g1 t) (g2 t)
but so far parameter declarations seem like about the right balancedeclaring parameter types in your own code doesn't help with code you didn't write, but you can use the repl to find out what types the compiler inferred for it
# List.map ;;
- : ('a -> 'b) -> 'a list -> 'b list =
presumably editors with lsp support have some magic keystroke to display this on demand in your editor or something, maybe an lsp user can tell us what it isRe: OCaml: a Rust developer's first impressions
#10OCaml is great, we learned it in class back in college, then we learned Rust right afterwards. Oftentimes people say OCaml is Rust without the borrow checker (or that Rust is OCaml with a borrow checker), but that's not quite true. Since it is entirely functional and recursive, it takes more time to wrap your head around. Now with OCaml 5, we also have algebraic effect support, something that Rust is looking to add i…