Live data from Hacker News

Why Functional Programming Matters (1984) [pdf]

cse.chalmers.se

11–20 of 145 posts

Re: Why Functional Programming Matters (1984) [pdf]

#11

A lot of pleas for functional programming give a long list of convincing examples that work well with functional programming. You can do this with almost any language, and this is also quite deceptional, as this is often done to convince beginners to learn another language; "look at how simple it is to program this contrived example in !". In order to be able to use a programming language or paradigm well, it is espe…

Functional programming largely has two schools: Treat "commands" as a separate entity from expressions, and bake "commands" into expressions. The former is largely Haskell, Clean, ... and the latter is exemplified by e.g., Standard ML or OCaml.

There are trade-offs between the two, but I definitely belong to the second school: we simply add an imperative subset to our functional language. This means we can exploit any efficiency trick an imperative program can do, including low-level stuff. The seasoned FP programmer will then proceed to encapsulate the efficiency trick in a abstract module such that the rest of the program doesn't have to worry about it. Of course, the price to pay for this is that you are losing purity. I think this is a fair trade-off but others disagree.

As for performance and memory usage: it is always a property of the architecture or system, not of the programming language. Dropping to a low-level language, such as C, usually doesn't buy you too much these days. What is more important is that most C compilers in use have vastly more time invested into optimizing routines than the typical FP compiler. Apart from that, you can easily mange the same kind of data in e.g., OCaml than you can in C.

The reason FP can beat the curve of performance in practice is because you operate at a higher level of abstraction. You have more attempts at writing the correct architecture, and it is easier to change over time. Since most real-world problems are heavily time-constrained, this makes them beat low-level solutions: when the C programmer has written the first working version, the FP programmer has tried 5 different solutions.

There is one area FP tends to fare poorly: CPU bound tasks where an inner-loop has to squeeze out performance (video encoding comes to mind). But most low-level programming fares poorly as well: either you use assembly, write GPU-level programs, use an FPGA or create your own ASIC/SoC solution for this. Also note that moving to faster solutions here costs an order of magnitude in time and in dollars: FPGAs are, relatively speaking, expensive beasts.

Re: Why Functional Programming Matters (1984) [pdf]

#12
post #4

For those whose browsers don't speak bare postscript, a pdf also exists: http://www.cse.chalmers.se/~rjmh/Papers/whyfp.pdf

Out of curiosity, which browsers do support native postscript rendering?

Konqueror supports it in the sense that it will embed the appropriate KPart, just as it would for e.g. PDF. How "native" you consider that is an open question.

Re: Why Functional Programming Matters (1984) [pdf]

#13

A lot of pleas for functional programming give a long list of convincing examples that work well with functional programming. You can do this with almost any language, and this is also quite deceptional, as this is often done to convince beginners to learn another language; "look at how simple it is to program this contrived example in !". In order to be able to use a programming language or paradigm well, it is espe…

> Functional programming does not work well in programs which handle a lot of states

From what I understand, isn't this what functional programming excels at?

Re: Why Functional Programming Matters (1984) [pdf]

#14
post #4

For those whose browsers don't speak bare postscript, a pdf also exists: http://www.cse.chalmers.se/~rjmh/Papers/whyfp.pdf

Out of curiosity, which browsers do support native postscript rendering?

Renders fine in Safari. I assume it uses pdf.js or something in the same vein though, the page scrolling is very slow.

Re: Why Functional Programming Matters (1984) [pdf]

#15

A lot of pleas for functional programming give a long list of convincing examples that work well with functional programming. You can do this with almost any language, and this is also quite deceptional, as this is often done to convince beginners to learn another language; "look at how simple it is to program this contrived example in !". In order to be able to use a programming language or paradigm well, it is espe…

That's one of the reasons I loved the "programming languages" course on coursera[0]. The course went through 3 languages, ML, Racket and Ruby giving 2 weeks to each language. And then spent time contrasting the weaknesses and strengths of the different languages and their paradigms.

[0]https://www.coursera.org/learn/programming-languages (Starts up again on the 9th of January :) )

Re: Why Functional Programming Matters (1984) [pdf]

#16
post #12

Earlier quoted context omitted.

Out of curiosity, which browsers do support native postscript rendering?

Konqueror supports it in the sense that it will embed the appropriate KPart, just as it would for e.g. PDF. How "native" you consider that is an open question.

Thanks. By native I meant it renders without plugins or any configuration by the user, on a default install of the browser.

Re: Why Functional Programming Matters (1984) [pdf]

#17
The top link on /r/haskell right now [1] is someone complaining that their program runs out of space due to a subtle interaction between laziness and IO. I think it's safe to say that we have tried laziness as the default and have learned that it's the wrong default, because it plays havoc with space and with IO.

[1] https://www.reddit.com/r/haskell/comments/5h6emf/haskell_run...

Re: Why Functional Programming Matters (1984) [pdf]

#18
post #4

For those whose browsers don't speak bare postscript, a pdf also exists: http://www.cse.chalmers.se/~rjmh/Papers/whyfp.pdf

Out of curiosity, which browsers do support native postscript rendering?

My Firefox does not.

Re: Why Functional Programming Matters (1984) [pdf]

#19

The top link on /r/haskell right now [1] is someone complaining that their program runs out of space due to a subtle interaction between laziness and IO. I think it's safe to say that we have tried laziness as the default and have learned that it's the wrong default, because it plays havoc with space and with IO. [1] https://www.reddit.com/r/haskell/comments/5h6emf/haskell_run...

No, that's not laziness per se, that's "lazy IO", something somewhat different.

EDIT: It's not even a lazy IO problem since no lazy IO functions are used there.

Re: Why Functional Programming Matters (1984) [pdf]

#20
post #19

The top link on /r/haskell right now [1] is someone complaining that their program runs out of space due to a subtle interaction between laziness and IO. I think it's safe to say that we have tried laziness as the default and have learned that it's the wrong default, because it plays havoc with space and with IO. [1] https://www.reddit.com/r/haskell/comments/5h6emf/haskell_run...

No, that's not laziness per se, that's "lazy IO", something somewhat different. EDIT: It's not even a lazy IO problem since no lazy IO functions are used there.

The problem is laziness. Lazy IO just makes it happen with files, which is more noticeable. In regular lazy code it happens with memory instead (space leaks).
Post reply on HN