Skip to main content
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 ...
Michael Homer's user avatar
  • 15.3k
29 votes

Are there Haskell-like languages where equations allow for arbitrary left-hand sides?

Curry does exactly this kind of stuff. ...
leftaroundabout's user avatar
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 ...
Jon Purdy's user avatar
  • 3,648
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 ...
Michael Homer's user avatar
  • 15.3k
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 ...
Adám's user avatar
  • 3,317
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 ...
Starship's user avatar
  • 1,518
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 ...
Jon Purdy's user avatar
  • 3,648
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 ...
RubenVerg's user avatar
  • 1,681
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 ...
Jon Purdy's user avatar
  • 3,648
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 ...
Alex Chichigin's user avatar
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 ...
Michael Homer's user avatar
  • 15.3k
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 ...
Chris Dodd's user avatar
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 ...
Alexis King's user avatar
  • 12.7k
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 ...
jwodder's user avatar
  • 180
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 ...
Michael Homer's user avatar
  • 15.3k
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 ...
list 'r's user avatar
  • 61
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 ...
lyxal's user avatar
  • 2,045
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 ...
Silvio Mayolo's user avatar
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 ...
Adamátor's user avatar
  • 1,095
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 ...
IMSoP's user avatar
  • 3,226
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 ...
alephalpha's user avatar
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 ...
ruakh's user avatar
  • 153
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; ...
Patrick Stevens's user avatar
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(...)))....
David Young's user avatar
  • 2,532
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 ...
Michael Homer's user avatar
  • 15.3k
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 ...
David Young's user avatar
  • 2,532
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 ...
Mario B.'s user avatar
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): ...
tarzh's user avatar
  • 4,509
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: ...
Alex Chichigin's user avatar
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 ...
ratchet freak's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible