4 ms·
Does it look like functional programming anymore ?
by ttoinou 9mo ago
Does it look like functional programming anymore ?
- le-mark 9mo agoI 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 9mo agoDepends 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 9mo agoEven 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 9mo agoLooks 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
- seanhunter 9mo agoLooks like 100% idiomatic normal OCaml to me.
- unstruktured 9mo agoTechnically you are right but too much mutation for my tastes and probably many other ocaml developers.
- avsm 9mo ago(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.
- boltzmann-brain 9mo agoYes - 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.