35
votes
Accepted
Why don't pure functional languages have object identity?
In a pure functional language, functions are referentially transparent — that is, any function call should be able to be replaced by its value, and vice-versa, without affecting the semantics of the ...
29
votes
Are there Haskell-like languages where equations allow for arbitrary left-hand sides?
Curry does exactly this kind of stuff.
...
18
votes
Are there Haskell-like languages where equations allow for arbitrary left-hand sides?
Yes, this is a feature of Agda, in the form of copatterns, and more generally in Mercury which is a functional logic language.
A data type is defined by its injections, or constructors, and eliminated ...
16
votes
Accepted
What are the disadvantages of lazy languages?
There are a lot of situations where lazy evaluation is beneficial and avoids unneeded calculation (like infinite lists in Haskell) or gives other benefits (like ...
16
votes
What are the pros and cons of automatically curried functions?
It introduces the limitation that a single function cannot take a variable number of arguments, since giving fewer than the maximum number of arguments will simply curry and return a function, rather ...
12
votes
Accepted
What are the pros and cons of automatically curried functions?
Some pros:
Being concise. It has less arguments and is more readable. It also enables partial functions.
Flexibility. It allows for more flexibility in function composition and permits creation of ...
12
votes
How to implement + in a language where functions accept only one argument?
I think this is cheating, because in the end the 2-ary + is used.
If the language has only 1-ary functions such a 2-ary + can not exist.
Not so—in GHC Haskell, the primitive operations are still ...
10
votes
Accepted
Is there a generic way to refer to the current function in recursion?
APL
A few APL dialects support the glyph ∇ inside a dfn (which is pretty much a lambda) which refers to the dfn itself. See Dyalog documentation on recursion.
(I ...
10
votes
Why are there different typeclass hierarchies?
The design of a typeclass hierarchy is guided by several competing concerns. What you’re asking about is mainly a tension between precision and ease of use.
Haskell and backward compatibility
If you ...
9
votes
Accepted
Runtime/Backend for a lazy, pure functional, lambda-calculus-based language?
I guess, the best-known modern optimizing back-end for lazy functional languages specifically (and strict ones too) is GRIN.
On the other hand, Pure Language for example is implemented directly on top ...
8
votes
Accepted
How does the map function work in stack-based languages?
The typed approach you describe generally is how typed stack-based languages work, sometimes with a little more flexibility when you have the stack before and after line up. You won't be permitted to ...
8
votes
Accepted
How do languages chain higher-order functions while still keeping performance?
Lazy Types
This is pretty much what you're talking about with your Rust example -- even if the language isn't lazy, it can support lazy types (either built-in or in a way the user can add them) to get ...
8
votes
Accepted
Possible ways for a system interface in a lazy LC language?
The standard approach: monadic I/O
Modern pure, functional programming languages have overwhelmingly standardized on monadic approaches for embedding sequential programs into a language that otherwise ...
8
votes
Is there a generic way to refer to the current function in recursion?
Forth
Recursion in Forth actually requires a construct like this, as a word is not visible inside its own definition. In order to recurse, you need to use the ...
7
votes
Does a Rust implementation of the Monkey programming language require a garbage collector?
This will depend on your implementation strategy, but anything that is heap-allocated needs to be freed somewhere if there is not to be a memory leak. Arrays, hash maps, and closures are prime ...
6
votes
Are there Haskell-like languages where equations allow for arbitrary left-hand sides?
Verse Calculus ($\mathcal{VC}$) is a newly-proposed core to a functional logic language that offers exactly this.
Equations in Verse can appear with the form
$e_1 = e_2$,
where $e_i$ is an arbitrary ...
6
votes
Accepted
Capturing from outer stack to lambda in a stack-based language?
This answer comes from an experience of using stack-based golfing languages like 05AB1E and Vyxal - a programming language I've made.
Both isolated and outer stack usage have their advantages and ...
5
votes
Capturing from outer stack to lambda in a stack-based language?
The Factor approach
Factor doesn't give functions an isolated stack, but it still has enough control to prevent functions from clobbering (accidentally or maliciously) the stack. A function must ...
5
votes
What are the pros and cons of automatically curried functions?
Worse error messages
In a non-curried language, if you forget an argument to a function, you get an error message saying so. In a curried language, this may silently create a partially-applied ...
5
votes
How to implement + in a language where functions accept only one argument?
I think this comment from benrg is a useful insight:
There is a binary operator in lambda calculus, namely function application. You could argue that it's a two-argument function.
In other words, we ...
5
votes
How does the map function work in stack-based languages?
I tried some stack-based or concatenative languages to see how the following codes work:
1 [2 3 4] {add} map
1 [2 3 4] {swap} map
1 [2 3 4] {dup} map
...
5
votes
Is there a generic way to refer to the current function in recursion?
In Perl — which is not primarily a functional language, but does support functional programming styles — the keyword __SUB__ is a reference to the current ...
5
votes
Is there a generic way to refer to the current function in recursion?
Mathematica, a definition of the factorial function:
If[#1 == 1, 1, #1 #0[#1 - 1]]&
(The ampersand indicates a definition of an anonymous function; ...
5
votes
Can total (primitive) corecursion be implemented?
Such elements correspond to infinite constructor applications. In the case of $\tilde{\mathbb{N}}$, the element at infinity will correspond to succ(succ(succ(...)))....
5
votes
Are there any programming languages that operate solely via side-effects?
There are many languages and language paradigms that operate solely via side effects, and if anything it's the languages that don't that are new on the scene. For example, many procedural programming ...
5
votes
What problems do applicative functors solve, as an abstraction relative to monads and arrows?
If you are only using the applicative interface, you're not able to make one action depend on the "results" of a previous action. The monad interface gives you that power.
For some type ...
4
votes
Are there Haskell-like languages where equations allow for arbitrary left-hand sides?
Probably the simplest paradigm that allows what you want is that of graph rewriting. One implementation for example was LEAN, the predecessor to the Clean programming language.
The trouble with ...
4
votes
Accepted
How can I design a Functor trait to handle trait?
Rust already has a way to represent Functor using Generic Associated Types (GATs):
...
4
votes
Accepted
Quantified variables without case-based analysis in traits
I suggest "stealing" syntax from Lean 4, it's pretty clean and concise, and doesn't depend on the case of variables or much punctuation:
...
4
votes
What is the mathematical abstraction of bitflags for use in a purely functional language?
It is a set.
The bitwise OR of 2 bitflag values results in the union of the 2 sets.
The bitwise AND of 2 bitflag values results in the intersection of the 2 sets.
The bitwise NOT of a bitflag value ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
functional-programming × 26functions × 5
lambda-calculus × 4
optimization × 3
syntax × 2
language-design × 2
implementation × 2
rust × 2
garbage-collection × 2
recursion × 2
monads × 2
algebraic-data-types × 2
runtime × 2
stack-based-languages × 2
currying × 2
compilers × 1
types × 1
language-comparison × 1
standard-library × 1
semantics × 1
control-flow × 1
type-systems × 1
haskell × 1
data-structures × 1
loops × 1