logoalt Hacker News

ttoinoutoday at 12:25 PM5 repliesview on HN

Does it look like functional programming anymore ?


Replies

boltzmann-braintoday at 3:08 PM

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.

seanhuntertoday at 2:42 PM

Looks like 100% idiomatic normal OCaml to me.

show 1 reply
le-marktoday at 12:59 PM

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.

show 1 reply
pjmlptoday at 1:25 PM

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.

show 1 reply
cess11today at 2:12 PM

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