News for hackers. Stuff that matters.
Re:Admitting That Functional Programming Can Be Awkward (2007) by dsabanin on Saturday October 24, 2020 @12:34PM (#24880216)
Functional programming was never about first-class functions. It was always about programming with pure and total functions in their mathematical version.
Re:Admitting That Functional Programming Can Be Awkward (2007) by acdha on Saturday October 24, 2020 @12:57PM (#24880402)
This may be true in your personal experience but that’s certainly not universal. A key distinction is when you learned this: 2-3 decades ago when most people were using languages without first-class functions, this was very commonly the most important feature mentioned because it was the most pronounced difference. That’s no longer emphasized as much now that this feature and related techniques has become mainstream.
Re:Admitting That Functional Programming Can Be Awkward (2007) by pyrale on Saturday October 24, 2020 @01:29PM (#24880629)
I believe the statement GP made has been true since the days of Church.

It is not surprising that "what's the difference between your language and mine" will yield an answer that is different than what you'll get if you ask "what is that concept you're trying to build a language after?"

Re:Admitting That Functional Programming Can Be Awkward (2007) by acdha on Saturday October 24, 2020 @02:01PM (#24880823)
That might be pointing out an important distinction: did you learn this formally from that academic community or elsewhere? As a global assertion it’s wrong but it could be accurately representative if you’re only talking about subcommunities in the former case.
Re:Admitting That Functional Programming Can Be Awkward (2007) by pyrale on Saturday October 24, 2020 @02:42PM (#24881085)
I have made another comment in this thread where I make a distinction between what people _try_ to achieve, and what tradeoffs they make on the way.

You are right that most functional languages do not have pure and total functions. However, the inspiration they take from is usually the pure/total functions as described above.

Re:Admitting That Functional Programming Can Be Awkward (2007) by adwn on Saturday October 24, 2020 @02:33PM (#24881030)
> It was always about programming with pure and total functions in their mathematical version.

Are you sure about this? A total function is defined for all of its possible inputs, i.e., it must always terminate. A functional programming language with only total functions isn't Turing complete.

Re:Admitting That Functional Programming Can Be Awkward (2007) by pyrale on Saturday October 24, 2020 @02:38PM (#24881057)
Several recent languages that came from the FP community recently tend to achieve this. This is the case of Agda, for instance, and I believe Idris also has totality checking.
Re:Admitting That Functional Programming Can Be Awkward (2007) by adwn on Saturday October 24, 2020 @02:51PM (#24881154)
Maybe you mean optional totality? As in, a function can be declared to be total and the compiler tries to prove it?

A language cannot be Turing-complete if it completely forbids non-termination, there is no way around this. Or stated differently: If a language is Turing-complete, then there are programs that don't terminate. If a Turing-complete language only has functions which are total (i.e., which always terminate), then it has another mechanism which allows non-termination, e.g. unbounded loops and mutable state.

Re:Admitting That Functional Programming Can Be Awkward (2007) by pyrale on Saturday October 24, 2020 @03:54PM (#24881543)
> A language cannot be Turing-complete if it completely forbids non-termination, there is no way around this.

I do acknowledge this. My point is that turing-completeness is not necessarily a desirable aspect of a language. You can check out Agda if you are interested in what can be done with a total language.

For some use-cases, like seting up a mainloop, you need an escape hatch because that mainloop is not going to be total. But not every program needs that. Conversely, a programming language that doesn't care about totality won't be able to sere other use-cases, such as building proven programs. My understanding is that it's much easier to build an escape hatch in total languages, than it is to retrofit non-total languages to prove programs.

Re:Admitting That Functional Programming Can Be Awkward (2007) by adwn on Sunday October 25, 2020 @12:57AM (#24883935)
> My point is that turing-completeness is not necessarily a desirable aspect of a language.

Ah, okay, I see.

> For some use-cases, like seting up a mainloop, you need an escape hatch because that mainloop is not going to be total. But not every program needs that.

Hmm, I would argue that in practice, nearly all programs will need that, because they're either potentially non-terminating (let's call this "type 1") or have a runtime with a bound which is not determined by any of its inputs ("type 2"). Examples for type 1 include firmware, kernels, drivers, database engines, any kind of server, all programs with a GUI, all REPLs, and many Unix-style utilities that process or generate streams (thing grep, cat, sed, dd). Examples for type 2 include all programs with non-blocking IO (because even if the input and output are known to be bounded, the number of read/write calls is potentially unbounded) and most programs which take a file name as input (because the file size is not part of the program's input).

That doesn't leave many exceptions. I admit, however, that in most cases you could structure your program so that it has a non-total mainloop which exclusively calls proven total functions. But I don't think this is very useful, because even in safety-relevant, hard real-time contexts, termination is not sufficient, but termination within a certain timespan.

Re:Admitting That Functional Programming Can Be Awkward (2007) by pyrale on Sunday October 25, 2020 @05:58AM (#24885102)
> That doesn't leave many exceptions.

Examples of programs which are useful and terminate are batch programs. Besides that, even in a server, you may want to ensure that a subset of the program terminates. For instance, if you're using a serverless architecture, knowing that your lambda will terminate may be useful.

Much like the separation between pure and impure functions in fp, having a distinction between total and non-total functions means that you can limit your non-total code to a couple dozen LoCs, which is a reasonable thing to manually check.

> But I don't think this is very useful, because even in safety-relevant, hard real-time contexts, termination is not sufficient, but termination within a certain timespan.

Once you've broken the non-termination issue, it becomes much more reasonable to start working on time estimates. Basically, once you've said that the number of instructions needed to solve the problem is a function of your input size, calculating that function becomes a possibility.

Re:Admitting That Functional Programming Can Be Awkward (2007) by dnautics on Saturday October 24, 2020 @03:11PM (#24881279)
That's not really true. Op is programming in erlang, which has never in it's history been pure functional, and specifically picked the functional paradigm for pragmatic reasons (function-internal immutability and limited global state gives the programmer guardrails), not for pure mathematical reasons.