Remix.run Logo
siwatanejo 9 days ago

IMO OCaml is mind-bending (e.g. go figure out the 'in' keyword, I still don't understand it), F# is much easier/simpler.

spider-mario 9 days ago | parent | next [-]

`let <var> = <expr> in <expr>` is an expression. Top-level bindings are just `let <var> = <expr>`. That’s pretty much all there is to it.

    let fac =
      let rec fac' acc = function
        | 0 -> acc
        | n -> fac' (n * acc) (n - 1)
      in
      fac' 1

    let seven =
      let four = 4 and three = 3 in
      four + three

https://ideone.com/HpTrI4
tuvix 9 days ago | parent | prev | next [-]

Never used OCaml but it seems like a way to chain together expressions using the same variable name? Seems odd but I could see myself using it

shikck200 9 days ago | parent | prev | next [-]

Ocaml is just an ML in the traditional sense. It keep scope without curlies. There is really not much else to it.

debugnik 9 days ago | parent | prev [-]

The 'in' keyword is purely syntax, like semicolons/newlines or braces in your language of choice.

siwatanejo 8 days ago | parent [-]

Yeah and it's fucking ugly and unreadable, it shouldn't be allowed.

mega_dean 8 days ago | parent [-]

That was my reaction at first, but I got used to it pretty quickly. Some of the other bizarre syntax bothered me for much longer, like using semicolons for list separators, eg [1;2;3] instead of [1,2,3].

I briefly tried to use Reason since it “fixed” a lot of my biggest issues with the syntax, but it wasn’t worth it overall so I went back to plain ocaml pretty quickly.

I didn’t look very closely at F# at the time, but I remember thinking it looked like “ocaml with more normal syntax”.