Live data from Hacker News

Why Functional Programming Matters (1984) [pdf]

cse.chalmers.se

81–90 of 145 posts

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

#81
post #11

Earlier quoted context omitted.

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 an…

The key insight is that immutability is not an end in itself, it's a tool to give us referential transparency. If a language can allow mutability in an area of code without allowing side effects to escape from it we can have all of the reasoning advantage that FP gives us at a level above the mutations. We can also have the performance we want.

The key insight is that immutability is not an end in itself, it's a tool to give us referential transparency.

How about a programming environment tailored for small simulations or games? I could imagine such an environment maintaining referential transparency without strict immutability. Rather, such a system could provide a kind of "poor-man's" immutability by only allowing pure functions that take state from tick N and output state for tick N+1.

Perhaps such a system could even achieve high performance by exploiting its constraints? Maybe the language could essentially be built on top of a custom VM and around the mechanism of bump allocation, read/write barriers, and Beltway garbage collection?

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

#82

Earlier quoted context omitted.

> The main gate to functional languages participating in, say, the Linux kernel is NOT that they are "too slow" or that "laziness makes them too confusing". It's that the Linux kernel is written entirely around the unique weirdness and expectations of C, and only languages based on or descendant to C do well there. Sure, but the usual functional style has intrinsic issues that prevent it from being feasible for writi…

> Sure, but the usual functional style has intrinsic issues that prevent it from being feasible for writing kernels in general. Not really? > A kernel (especially a microkernel) spends most of its time managing state. So does every computer program though. The idea that functional languages can't support mutation is a strangely persistent myth even in the face of multiple counter-examples AND 20 years of improvement…

A kernel spends most of it's time managing mutable state.

Here's a table of processes. We want it to be an array, rather than a linked list, for efficiency reasons. When a new process is created, we don't want to copy the array, also for efficiency reasons. So we mutate the array.

> So does every computer programmer though.

Not really.

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

#83

Earlier quoted context omitted.

Does COGENT look functional or imperative in programming style to you? Genuine question as I don't do FP. COGENT is latest in attempts at bringing functional, verified languages into system space. A team already redid the ext2 filesystem with it. https://ts.data61.csiro.au/projects/TS/cogent.pml

COGENT takes pretty much precisely the approach I described below: it uses domain-specific structures in a functional language to encode verified imperative code. If you look at pretty much any code in the ext2 pilot (here[1] is as good as any) you'll notice that a lot of the functions called are things like destroy_Ext2DirEnt (which unless they named things poorly, takes a clear action), as well as a lot of passing…

Thanks for the insightful reply. I agree that code does look very imperative. Likely due to goal of C synthesis as you said.

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

#84

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…

I don't believe many are advocating functional programming as a replacement for hand-crafted C, but it is a good alterative to imperative high-level languages which often make big performance sacrifices but offer only small improvements in reliability and abstraction/composition. I absolutely believe the correct way to build software is with language layers. Ideally using FP or declarative languages where you can. Python gets this partially right by using C libraries for all its performance critical work. C++ is IMHO the wrong approach, a jack of all trades and a master of none.

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

#85

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.

I'd say this is completely false, and almost no one agrees with this if they've done any actual functional programming.

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

#86

Earlier quoted context omitted.

> Sure, but the usual functional style has intrinsic issues that prevent it from being feasible for writing kernels in general. Not really? > A kernel (especially a microkernel) spends most of its time managing state. So does every computer program though. The idea that functional languages can't support mutation is a strangely persistent myth even in the face of multiple counter-examples AND 20 years of improvement…

A kernel spends most of it's time managing mutable state. Here's a table of processes. We want it to be an array, rather than a linked list, for efficiency reasons. When a new process is created, we don't want to copy the array, also for efficiency reasons. So we mutate the array. > So does every computer programmer though. Not really.

> A kernel spends most of it's time managing mutable state.

Why do you think that FP doesn't have tools for this? Do you genuinely think that in 20+ years of research no one has thought of this? Have you investigated it?

I don't know. If you think that things like ST aren't suitable please say why (other than the larger problems with monad transformers, of course).

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

#87
post #85

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. I'd say this is completely false, and almost no one agrees with this if they've done any actual functional programming.

I'd say that state is actually easier to handle in functional languages. You just need the right abstractions for it.

I've been working with Phoenix lately, which basically just hands request/response details down a pipe of functions, which all can change the state of the response. There can be a lot of state contained in this response, but when you use Phoenix, you don't really notice it. The abstraction makes everything seamless - best web-framework I've used to date.

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

#88
post #27

Earlier quoted context omitted.

>"It does not work well in programs which have high requirements for performance or memory" Can you elaborate on why this is? I see the parent post mentioned "lazy evaluation." Can you say why this is relevant to discussions on resource utilization and performance?

Higher levels of abstraction are harder to translate to efficeint machine code. Non-strict (what you call "lazy") evaluation can make it more difficult to predict when resources are needed. In strict languages, the resources needed to evaluate f() are needed exactly at the point where you typed "f()". With non-strict evaluation, those resources may be needed then, later, or not at all! If those resources happen to be…

That makes total sense. Thanks for the explanation.

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

#89

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…

I'm too much of a noob to know what I'm talking about but so far this series of talks has convinced me FP with strong typing brings something new to the table in the same way that say C brings something over assembly and s expressions in lisp bring something over non s expression languages.

http://fsharpforfunandprofit.com/

In particular this example convinced me I'm missing out on something

http://fsharpforfunandprofit.com/posts/designing-for-correct...

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

#90

Earlier quoted context omitted.

> Sure, but the usual functional style has intrinsic issues that prevent it from being feasible for writing kernels in general. Not really? > A kernel (especially a microkernel) spends most of its time managing state. So does every computer program though. The idea that functional languages can't support mutation is a strangely persistent myth even in the face of multiple counter-examples AND 20 years of improvement…

A kernel spends most of it's time managing mutable state. Here's a table of processes. We want it to be an array, rather than a linked list, for efficiency reasons. When a new process is created, we don't want to copy the array, also for efficiency reasons. So we mutate the array. > So does every computer programmer though. Not really.

> Here's a table of processes. We want it to be an array, rather than a linked list, for efficiency reasons.

At least in Linux, the table of processes is implemented as a (doubly) linked list.

Post reply on HN