Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

If it's functional (recursion vs imperative loops) most people/organizations will not use it. At this point that is just the reality.


I really wish people would quit pushing "functional". People equate that with "My programming is now always a recursive logic puzzle."

Talk about "immutable by default". Talk about "strong typing". Talk about "encapsulating side effects". Talk about "race free programming".

Those are the things that programmers currently care about. A lot of current Rust programmers are people who came there almost exclusively for "strong typing".


Having loops is not the defining feature that separates functional from imperative. Where did this idea come from? I'm suddenly seeing it in a lot of places.


It is not the defining feature but loss of the loop is one of the most obvious differences for people who look at a functional language Rust has immutability, pattern matching, etc, but it remains an imperative language with "some functional features". Or this is my subjective analysis.


So is Haskell not functional? Or an imperative language with some functional features?

    -- ghci> example
    -- Triangular number 1 is 0
    -- Triangular number 2 is 1
    -- Triangular number 3 is 3
    -- Triangular number 4 is 6
    -- Triangular number 5 is 10
    example = runEff $ \io -> evalState 0 $ \st -> do
      for_ [1..5] $ \i -> do
        n <- get st
        let msg = "Triangular number " <> show i <> " is " <> show n
        effIO io (putStrLn msg)
        st += i
    
      where
        st += n = modify st (+ n)
(This is not a trick question. Simon Peyton Jones described Haskell as "the world's finest imperative language" [1], and I agree. This code is written using https://hackage.haskell.org/package/bluefin)

[1] Tackling the Awkward Squad: monadic input/output, concurrency, exceptions, and foreign-language calls in Haskell


But, again, loops aren't automatically imperative per se. Consider loop / recur in Clojure for an example. For someone coming from JavaScript, it's not really much different from writing a while loop where every branch has to terminate with an explicit break or continue.


You can be functional "in spirit" more than purely functional. OCaml and Standard ML falls into this category. Ocaml has loops for instance. You might just not see many loops if code is written by OCaml developers, because there's frankly no need to use them in a lot of places. You often want to lift the abstraction level of iteration to an arbitrary data structure such that you get freedom of implementation. See Applicative and Monad.


its a simplification of immutability and its consequences




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: