News for hackers. Stuff that matters.
Re:Why Functional Programming Matters (1984) [pdf] by KirinDave on Thursday December 08, 2016 @11:35AM (#13131502)
> 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 via research and practical work.

> but you won't be writing code that looks remotely functional.

Many useful & powerful functional abstractions can be written to use constant space, even in Haskell.

Re:Why Functional Programming Matters (1984) [pdf] by johncolanduoni on Thursday December 08, 2016 @12:28PM (#13132100)
My point is not that functional languages can't support mutation, I'm well aware of the whole gamut from State to F-Star, Eff, and Idris. My point is that you're going to spend almost all of your time explicitly mutating things, using whatever functional language as a "very fine imperative language."

Yes, you can embed those semantics inside functional semantics, and even use the functional language to add more static verification at the type level via things like F-Star's Hoare logic. But you're still mostly going to shoving bits in specific places based on the result of a shallow pure function applied to bits you yanked from a specific place.

On top of that, you're not going to be able to abide the kind of allocations that functions in Haskell, OCaml, etc. can do with little provocation (and which are hard to avoid categorically), so you'll need to work within an especially restrictive DSL. Definitely no lambdas or partial application. So in the end you'll be in "Generic Stack-focused Pointer-pushing Procedural Imperative Language: The Monad". Where in this do you see any functional-ness, outside of the fact that you'll probably call your procedures functions?

> Many useful & powerful functional abstractions can be written to use constant space, even in Haskell.

Yes, but not to the degree that Atom's use cases require (where the program must allocate all memory ahead of time and therefore know a specific upper bound). This necessitates deviation from usual practices of any kind, including Haskell's.

Re:Why Functional Programming Matters (1984) [pdf] by KirinDave on Thursday December 08, 2016 @01:10PM (#13132539)
> My point is not that functional languages can't support mutation, I'm well aware of the whole gamut from State to F-Star, Eff, and Idris. My point is that you're going to spend almost all of your time explicitly mutating things, using whatever functional language as a "very fine imperative language."

The difference being that this "very fine imperative language" has much stronger type safety guarantees.

Maybe we can stop having ring0 buffer overflows some day when C programmer pride is sufficiently assuaged. I doubt it though... My experience with the linux kernel community is that it is a limitless void of insecurity and infighting.

> On top of that, you're not going to be able to abide the kind of allocations that functions in Haskell, OCaml, etc. can do with little provocation

OCaml does much better here (in fact, really quite amazingly well here, on part with some of the greatest common lisp distribution compilers which were stunningly good at it). But yeah, Haskell has a very poor focus on the needs of the "industry" when said industry is focused around extremely tight optimizations.

That said, I refuse to confuse a specific example of FP with a traditionally academic and research focus with the discipline as a whole. That's a dodge.

> So in the end you'll be in "Generic Stack-focused Pointer-pushing Procedural Imperative Language: The Monad".

Honest question: what's the problem with this if it offers additional safety and promotes the use of stateless functions? If it all compiles down to similar code, then it's fine. People act like monadic code is not functional, when it is in fact extremely functional code.

That's what's funny about all this: imperative programming is expressible succinctly and easily in functional languages.

Re:Why Functional Programming Matters (1984) [pdf] by johncolanduoni on Thursday December 08, 2016 @01:31PM (#13132752)
It's not a problem at all, it's exactly the direction I'd like to see things go as well. It's just that your code is still a stranger in a strange land in these cases. Your proofs will be full of the typical halmarks of functional programing, and for the stuff that is executed at runtime you'll definitely want some pattern matching, but there will be no closures or higher-order functions and limited opportunities for monads, functors, etc.

Would you consider a C program transliterated into a representation of C inside a functional language and then annotated with proofs to be "functional"? My argument is what you get if you write a true kernel (no sitting on top of a runtime written in something else) is going to look a lot like that would.

Re:Why Functional Programming Matters (1984) [pdf] by AnimalMuppet on Thursday December 08, 2016 @03:12PM (#13133841)
> The difference being that this "very fine imperative language" has much stronger type safety guarantees.

Is that a result of the specific language, rather than FP?

That is: One could think about building a procedural language that had... well, I'm not sure it could have Hindley-Milner types, because I'm not sure it could have higher-kinded types, but it could come close, couldn't it?

And from the other side: Does FP require very strong types? Or can it be done with something equivalent to C/C++'s type system? Or Python's?

Re:Why Functional Programming Matters (1984) [pdf] by AnimalMuppet on Thursday December 08, 2016 @02:01PM (#13133043)
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] by KirinDave on Thursday December 08, 2016 @02:28PM (#13133324)
> 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] by AnimalMuppet on Thursday December 08, 2016 @03:28PM (#13133970)
I know that FP has tools for that. But if the problem is primarily managing mutable state, isn't a tools that lets you directly see what you're doing a better fit?

Are the FP tools as efficient as the direct, C-style approach? For an OS, that matters.

Are the FP tools as easy to reason about correctly (especially in a section you're not familiar with)? For an OS that's worked on by thousands of people, that matters.

In this context, what is "ST"? And, what are the larger problems with monad transformers?

Re:Why Functional Programming Matters (1984) [pdf] by KirinDave on Thursday December 08, 2016 @04:28PM (#13134464)
What's most frustrating about these conversations is what I've noted in another thread: people feel really comfortable talking about what FP can and can't do without even acquainting themselves with 10+ year old techniques in the field.

I'm sorry, I decline to continue this conversation further.

Re:Why Functional Programming Matters (1984) [pdf] by pjmlp on Friday December 09, 2016 @12:36AM (#13136894)
How do you think Xerox PARC, Genera and TI managed to write Lisp based OSes?
Re:Why Functional Programming Matters (1984) [pdf] by lispm on Friday December 09, 2016 @02:36AM (#13137315)
By using all the imperative, procedural and object-oriented features of Lisp.

In many ways the early MIT Lisp Machine morphed into a Flavors Machine in the early 80s.

Remember, Lisp is a multi-paradigm language.

Re:Why Functional Programming Matters (1984) [pdf] by pjmlp on Friday December 09, 2016 @04:43AM (#13137744)
But that is the thing, none of the successful FP languages in the industry are pure FP, rather multi-paradigm, even if functional first.
Re:Why Functional Programming Matters (1984) [pdf] by warkdarrior on Thursday December 08, 2016 @02:55PM (#13133649)
> 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.

Re:Why Functional Programming Matters (1984) [pdf] by KirinDave on Thursday December 08, 2016 @04:26PM (#13134452)
I wasn't going to say anything but...
Re:Why Functional Programming Matters (1984) [pdf] by AnimalMuppet on Friday December 09, 2016 @11:24AM (#13139630)
TIL.