News for hackers. Stuff that matters.
Re:Functional programming is not popular because it is weird... by brundolf on Monday September 13, 2021 @02:31PM (#28514968)
Something I've wondered is why we can't have a language that looks totally procedural but uses monads under the hood to reason about state at any given point in the process. This would mostly be sugar, but I think it could make that stuff much more accessible.

We get small, specialized fragments of this in Rust's borrow-checker and TypeScript's control-flow analysis, but I'm not aware of something that tries to take the whole of IO-monads and reshape them into a familiar format.

Re:Functional programming is not popular because it is weird... by Y_Y on Monday September 13, 2021 @02:59PM (#28515323)
What about Haskell?

  do
    putStr "What is your first name? "
    first <- getLine
    putStr "And your last name? "
    last <- getLine
    let full = first ++ " " ++ last
    putStrLn ("Pleased to meet you, " ++ full ++ "!")
(see: https://en.m.wikibooks.org/wiki/Haskell/do_notation )
Re:Functional programming is not popular because it is weird... by amusedcyclist on Monday September 13, 2021 @11:37PM (#28519947)
Gets a bit uglier if you use >>= instead lol
Re:Functional programming is not popular because it is weird... by zeugmasyllepsis on Monday September 13, 2021 @04:07PM (#28516137)
This might work out well in practice when tracking a single effect with a monad (e.g. with Haskell's `do` notation) but I think it quickly falls apart when working with multiple effects. Monads don't have a general form of composition - at the very least the order that they're composed matters to the outcome of the program. Procedural code is generally flexible enough to allow you to mix-and-match how effects gets handled, which I think would be difficult and impractical to work out in monadic contexts.
Re:Functional programming is not popular because it is weird... by zozbot234 on Monday September 13, 2021 @05:12PM (#28516941)
If you want to mix and match effects without regard to order of composition, that's what Lawvere theories are for (commonly known as 'algebraic effects'). You're right that monads don't give you this, but there are ways of describing these patterns without resorting to "procedural" idioms.
Re:Functional programming is not popular because it is weird... by zozbot234 on Monday September 13, 2021 @02:44PM (#28515118)
Rust's borrow checker (or rather its affine typing, which the borrow checker partly implements - "affine" rather than linear, b/c the compiler is free to drop() objects that are no longer used) actually gets in the way of using monads to reason about state. That's one key reason why the language still lacks a general monad construct.
Re:Functional programming is not popular because it is weird... by AnimalMuppet on Monday September 13, 2021 @11:27PM (#28519868)
It seems to me that if it looks totally procedural, then most programmers are going to reason about it totally procedurally. Using monads under the hood isn't going to buy you anything. In particular, it isn't going to make FP any more accessible, because the programmers won't be doing FP. They'll be doing procedural programming. Sure, the language may turn it into FP under the hood, but that's a detail of how the compiler generates its intermediate forms. That's not the claimed magic of FP; it's all in how you think. And if you think you're doing procedural, well... you don't get any FP magic that way.
Re:Functional programming is not popular because it is weird... by garethrowlands on Tuesday September 14, 2021 @04:22AM (#28521796)
True enough, when you're writing imperative Haskell, you're not hitting the claimed magic of FP.

But:

1. Haskell lets your write the majority of your code in pure style. And it helps you separate the imperative parts (like pure core, imperative shell).

2. The compiler tries hard to generate the same machine code as C. The difference is that it gives the programmer more options: because the imperative parts are values (actions), it's strightforward to calculate them, which you can't do in C (you'd need the preprocessor or maybe LISP macros).