Remix.run Logo
ttoinou 9 hours ago

Does it look like functional programming anymore ?

boltzmann-brain 7 hours ago | parent | next [-]

Yes - high-performance Haskell code looks similar. There isn't much to be said there - it's a little less clean-looking because FP optimizes for the most useful scenario and trying to do highly advanced stuff like that will be more verbose. This is in contrast to OOP where everything is verbose, and sometimes high-perf stuff that falls into the shape of globals + mutation + goto looks very succinct.

seanhunter 7 hours ago | parent | prev | next [-]

Looks like 100% idiomatic normal OCaml to me.

unstruktured 7 hours ago | parent [-]

Technically you are right but too much mutation for my tastes and probably many other ocaml developers.

avsm 6 hours ago | parent [-]

(author here) The mutation is only for performance critical code. I'm first trying to match C/Rust performance in my code, and then transform it to more idiomatic functional code (which flambda2 in OxCaml can optimise).

It's too difficult right now to directly jump to the functional version since I don't understand the flambda2 compiler well enough to predict whta optimisations will work! OxCaml is stabilising more this year so that should get easier in time.

le-mark 9 hours ago | parent | prev | next [-]

I think there are more succinct snippets in here and some this more verbose exposition is for pedagogical purposes. I am not a fan of ocaml because tacking on the object syntax made SML more verbose (ugly imo). Looks like 0xcaml continued trend.

pjmlp 8 hours ago | parent [-]

OxCaml is OCaml, it is only a set of language extensions that Jane Street expects eventually being able to upstream, depending on the experience.

pjmlp 8 hours ago | parent | prev | next [-]

Depends on what one means as FP.

When I learnt FP, the choice was between Lisp, Scheme, Miranda, Caml Light and Standard ML, depending on the assignment.

Nowadays some folks consider FP === Haskell.

ttoinou 8 hours ago | parent [-]

Even F# looks like good FP to me. But yes I expect something short in FP to clearly see the structure of the program, side effects, flow and data

cess11 8 hours ago | parent | prev [-]

Looks pretty ML:ish to me, even in a segment like this:

   let parse_int64 (local_ buf) (sp : span) : int64# =
     let mutable acc : int64# = #0L in
     let mutable i = 0 in
     let mutable valid = true in
     while valid && i < I16.to_int sp.#len do
       let c = Bytes.get buf (I16.to_int sp.#off + i) in
       match c with
       | '0' .. '9' ->
         acc <- I64.add (I64.mul acc #10L) (I64.of_int (Char.code c - 48));
         i <- i + 1
       | _ -> valid <- false
     done;
     acc