8 ms·
Can't for the life of me figure out why people equate FP with the abomination that Haskell is. Erlang is FP. Javascript is FP. Ocaml is FP. Type classes, or a
by dmitriid 9y ago
Can't for the life of me figure out why people equate FP with the abomination that Haskell is.
Erlang is FP. Javascript is FP. Ocaml is FP.
Type classes, or anything else that has "types" in them such as dependent, or liquid, are not FP, they are types. Types that found their way into a couple of FP languages.
- farresito 9y agoWhat makes you say Haskell is an abomination?
- dmitriid 9y agoShort version: You need a PhD in type theory to get anywhere. Basically every obscure overly complicated concept that Haskell throws at you (all the while pretending to be the only true FP language out there) can be explained in 5 to 10 lines of Javascript: https://github.com/hemanth/functional-programming-jargon https://github.com/hemanth/functional-programming-jargon Compare and contrast. - Monad explained in Javascript: https://github.com/hemanth/functional-programming-jargon#monad https://github.com/hemanth/functional-programming-jargon#mon... - Timeline (sic!) of monad tutorials for Haskell: https://wiki.haskell.org/Monad_tutorials_timeline https://wiki.haskell.org/Monad_tutorials_timeline The worst crime against humanity though is Haskell crap seeping into other languages (such as ramda, for instance: http://ramdajs.com http://ramdajs.com)
- willtim 9y agoYou certainly would need a PhD to fully understand Monads from that small JavaScript snippet. The Haskell link you gave gives Phil Wadler's original paper as the first link. It is easy to read, explains everything beautifully and full of many examples. Learn some basic Haskell for no other reason than to read seminal papers such as these. To favour some random JavaScript hacker on the internet and steer others away from the original work is anti-intellectualism.
- dmitriid 9y agoAh, here comes the condescending tone I've so come to appreciate from the Haskell programmers. "Go and read", "anti-intellectualism".
- willtim 9y agoYou are misquoting me. I said steering others away from the original source of work to an interior source (incomplete at best) is anti-intellectualism. I do not mean to be condescending, but I feel very strongly about this.
- dmitriid 9y agoIn order not to copy-paste, I'll link to my reply in another thread: https://news.ycombinator.com/item?id=14890766 https://news.ycombinator.com/item?id=14890766
- eastWestMath 9y agoWadler's paper is an excellent piece of exposition that's us at the level of an upper-year undergraduate textbook. There's nothing condescending about referring a professional to a relevant paper in their discipline, but it is troubling when a professional won't even read over a paper.
- KirinDave 9y ago
- tome 9y ago> Basically every obscure overly complicated concept that Haskell throws at you (all the while pretending to be the only true FP language out there) can be explained in 5 to 10 lines of JavaScript So presumably the same concepts can be explained in 5 to 10 lines of Haskell too. I think you're confusing the refinement and polishing of ideas that's taken place in Haskell over the last two decades with the succinct presentation of those ideas once they've been worked out.
- dmitriid 9y agoBut they can't, can they. Or we wouldn't have the bazillion monad tutorials. The funny thing, this is the trouble that plagues other Haskell-inspired work (such as Purescript)
- tome 9y agoIt's obvious that the concept of monad can either be explained in 5-10 lines in both JavaScript and Haskell, or neither. Which are you claiming?
- dmitriid 9y agoIt's not obvious. I'm claiming that: - the concept of monad can be explained in 5-10 lines in Javascript (demonstrable) - the concept of a monad requires multiple years and tens of tutorials in Haskell (also demonstrable)
- mrkgnao 9y agoDemonstrate a pair of tutorials aimed at the same level of reader, one in JS, and one in Haskell, where you end up with a better understanding of the idea of a monad reading the former (as opposed to the implementation of the Monad instance for a list).
- dmitriid 9y agoTIL there's some "idea of a monad". Basically this is (in my mind) what's wrong with Haskell: it's overly concerned with the Platonic ideal. Meanwhile that one page on jargon has shown me that I effortlessly implement any and all of those things daily (and understanding what I'm doing) without the need to understand "an idea". I just use the tool that solves the problem. If someone insists on calling this "monadic composition", or "lifting over typeclasses", or "zygohistomorphic prepromorphisms", so be it.
- mrkgnao 9y ago> You need a PhD in type theory to get anywhere. That is extremely false. Haskell isn't even a good playground for academic type theory -- you'd want Agda etc. for that. The development of the language over the last few years has been characterized by pragmatism and a focus on backwards-compatibility, which is why you can take code from something like ten years ago and have it run without issues on modern versions of the Haskell compiler with little to no modifications. (Let's not talk about how long code written in "modern" JS lasts.) And I'd really like to see type class constraint resolution with functional dependencies, or Hindley-Milner type checking, or something of that sort implemented in "5-10 lines" of JS. "There he goes again with his mumbo-jumbo," you say. That's right, you don't need to care about those things to write Haskell. What you meant is implementations of typeclasses ("interfaces") like Monad, Functor, and so on: they don't take much more code in Haskell. Array.prototype.chain = function (f) { return this.reduce((acc, it) => acc.concat(f(it)), []) } instance Monad [] where xs >>= f = concat (map f xs) return = pure And we didn't even have to go the "this" route! Notice that your 5 - 10 lines of JS don't let you write code that works in any monad, whereas I can easily write whenM :: Monad m => m Bool -> m () -> m () whenM cond action = do condition <- cond if cond then action else pure () In Elm, you'd have List.whenM, Array.whenM, Maybe.whenM, ... or a straight-up false type signature like their Eq ones, and in JS, a bunch of prototype methods with no unifying threads. -- As for an example of why I think Haskell has the right ideas (few of us will say it's the "best language evar"): I'd really like to see a JS version of the Servant library, which takes an API spec for a server and actually generates a fully functional server from that. Here's a description: https://news.ycombinator.com/item?id=14149200 https://news.ycombinator.com/item?id=14149200 Does this strike you as idle theoretical self-enjoyment?
- dmitriid 9y ago> This is extremely false [referring to "You need a PhD in type theory to get anywhere."] almost immediately followed by > And I'd really like to see type class constraint resolution, or Hindley-Milner type checking You don't even see the irony in that, do you? > they don't take much more code in Haskell: riiight. I won't even go into the number of things that need to be explained there before you even start explaining what the code does.
- ykler 9y agoI don't think many people (and not the parent) "equate" FP with Haskell, but Haskell is in a way the most functional mainstream language because it is the only lazy one. You can have a purely functional language without laziness in principle, but, as Simon Peyton-Jones points has said, laziness, despite having serious costs, keeps a language designer honest by making it impossible to add side effects. The non-lazy languages all have side effects. A language like OCaml can still be relatively functional because of the way it is typically used. While JavaScript is not traditionally used in a functional way but can be. http://www.cs.nott.ac.uk/~gmh/appsem-slides/peytonjones.ppt http://www.cs.nott.ac.uk/~gmh/appsem-slides/peytonjones.ppt
- dmitriid 9y ago> Haskell is in a way the most functional mainstream language 1. Is it the most functional language because it's lazy? No 2. Is it the most mainstream language because it's lazy? No 3. Is it the most functional mainstream language because it's lazy? No + no = no Laziness does not a functional language make. > You can have a purely functional language What would be the purpose of a pure FP? Oh. There would be no purpose. > laziness ... keeps a language designer honest by making it impossible to add side effects wat Laziness is delayed execution. That's it. There's _nothing_ stopping you from delaying a side effect.
- foldr 9y ago>Laziness is delayed execution. That's it. There's _nothing_ stopping you from delaying a side effect. This is true, but unconstraimed side effects are too difficult to reason about in a lazy language to make them practical. So in practice, very few lazy languages have unconstrained side effects.
- chriswarbo 9y ago> Laziness is delayed execution. That's it. There's _nothing_ stopping you from delaying a side effect. Laziness is about more than just side effects. I think "evaluation" or "reduction" would be better words than "execution" here. Laziness (call by need) is an evaluation strategy for (beta-)reducing expressions, which has two nice properties: - If an expression can be reduced without diverging by some evaluation strategy, then it can be reduced without diverging using call by need. - Efficiency, in the sense that no duplicated work is performed. The other common evaluation strategies are call by name and call by value. Call by name has the first property, but not the second; so there are cases when it's exponentially slower than call by need. Call by value has the second property, but not the first, so there are cases when it diverges unnecessarily. This 'unnecessary divergence' is a major reason why most programming languages end up overly complicated to understand (at least, mathematically). For example, consider something like a pair `(cons x y)`, and its projection functions `car` and `cdr`. We might want to describe their behaviour like this: ∀x. ∀y. (car (cons x y)) = x ∀x. ∀y. (cdr (cons x y)) = y This is perfectly correct if we're using call by name or call by need, but it's wrong if we're using call by value. Why? Because under call by value `(car (cons x y))` and `(cdr (cons x y))` will diverge if either `x` or `y` diverges. Since the right-hand-sides only contain one variable each, they don't care whether or not the other diverges. This is why Haskell programs can focus on constructing and destructing data, whilst most other languages must concern themselves with control flow at every point (branching, looping, divergence, delaying, forcing, etc.).
- willtim 9y agoWhat definition of FP are you using? Because if it's just first-class functions, even Visual Basic has this now.
- dmitriid 9y agoExactly. Let's take Wikipedia: -- start quote -- In computer science, functional programming is a programming paradigm—a style of building the structure and elements of computer programs—that treats computation as the evaluation of mathematical functions and avoids changing-state and mutable data. It is a declarative programming paradigm, which means programming is done with expressions[1] or declarations[2] instead of statements. In functional code, the output value of a function depends only on the arguments that are passed to the function, so calling a function f twice with the same value for an argument x will produce the same result f(x) each time -- end quote --
- willtim 9y agoOnly Haskell strictly conforms to that definition. None of your other examples do.
- dmitriid 9y agoNo. It only means that other languages support multiple paradigms. Haskell doesn't strictly conform either, because it allows side effects (event though it's "only through escape hatches"). There's no such thing as a "pure functional programming language". Let's take it from the top: "In computer science, functional programming is a programming paradigm—a style of building the structure and elements of computer programs—that treats computation as the evaluation of mathematical functions and avoids changing-state and mutable data." All of the languages I listed support this style. The moment you write an IO monad inside a function in Haskell, you break the illusion of Haskell's strict conformation to the definition.
- willtim 9y agoNow you have the condescending tone! However, it appears you don't understand the IO monad. Programming using the IO monad is pure functional programming with full referential transparency. Please read Phil Wadler's paper, you will not understand this from that JavaScript snippet. The only backdoors are escape hatches like unsafePerformIO which are used for low-level libraries and FFI, they can be disabled with pragmas and/or compiler switches. It is much harder to stay true to that definition using the other languages, multi-paradigm or not. That is why Haskell is so often mentioned in the context of FP.