Questions tagged [functional-programming]
For questions regarding functional programing concepts like immutability, closures, pure functions, and monads or regarding functional languages which enforce some or all of these constraints.
26 questions
4
votes
1
answer
274
views
Why are there different typeclass hierarchies?
What's the history and reasoning behind the differences in the typeclass hierarchies in various functional programming language standard libraries? For instance, why does ...
7
votes
1
answer
474
views
What problems do applicative functors solve, as an abstraction relative to monads and arrows?
TL;DR
This site is of course particularly interested in the language designer's and implementor's perspective so, following What is an arrow and what powers would it give as a first class concept in a ...
0
votes
1
answer
497
views
Are there any programming languages that operate solely via side-effects?
Out of curiosity I checked how Google AI would respond to a similar question. The bot seemed clever enough to understand the question, but responded that functions in this case would have no return ...
6
votes
0
answers
330
views
What challenges might still prevent compiler or JIT optimizations of common FP operations like map, filter, and reduce?
(While I'm referring to JS in my example, I don't intend to be constrained to JS: so any comments/answers concerning FP-style APIs for working with collections for any language are welcome and ...
3
votes
2
answers
447
views
Does a Rust implementation of the Monkey programming language require a garbage collector?
Awhile back I wrote a Rust implementation of the Monkey programming language by Thorsten Ball (https://monkeylang.org/). When I got done with it I was a bit surprised that I never used an Arc/Rc ...
9
votes
2
answers
487
views
Can total (primitive) corecursion be implemented?
I'm trying to understand how to implement corecursion in a total functional context. I've already implemented recursion using standard techniques (for loops) but I ...
7
votes
2
answers
770
views
When do functional programming languages need advanced garbage collection?
While thinking about garbage collection, I realized a simple fact that a garbage collector that is more than reference counting is needed because there are circular references, but there are ...
1
vote
2
answers
371
views
What is the mathematical abstraction of bitflags for use in a purely functional language?
A lot of C APIs like to have something called bit flags to signal the functions configuration options like Vulkan, OpenCL, SQLite and much more, it a typical pattern to it.
This common pattern of ...
9
votes
7
answers
2k
views
Is there a generic way to refer to the current function in recursion?
In writing recursive functions (functional style), I often need to refer to the current function (depending on the context).
e.g.
f 0 = 0
f (S n) = f n + 2
Are ...
6
votes
3
answers
3k
views
How to implement + in a language where functions accept only one argument? [closed]
While reading about currying, I found the argument that it is beneficial in languages, which have only functions accepting only one argument.
I am wondering how to implement a 2-ary function like the ...
30
votes
5
answers
5k
views
Are there Haskell-like languages where equations allow for arbitrary left-hand sides?
In Haskell, you can define algorithms by equations that pattern-match on left-hand side constructors. For example:
...
5
votes
2
answers
936
views
How does the map function work in stack-based languages?
In many languages, the map function takes a function and a list, and applies the function to each element of the list, returning a new list of the results. Some ...
9
votes
2
answers
3k
views
How do languages chain higher-order functions while still keeping performance?
How do different programming languages deal with the chaining of higher-order functions (ex. [1,2,3].foldl((a, b) => a+b, 0), ...
15
votes
3
answers
991
views
Towards a better default listlike datastructure for functional languages
In most functional languages I know of, linked lists are the default datastructure of choice for many operations. The benefits are clear - they're clearly encoded with ADTs, and can be utilised easily ...
3
votes
1
answer
363
views
How can I design a Functor trait to handle trait?
In programming languages like Rust, variables of different types that implement the same trait can have different sizes, i.e., the number of bytes used in the memory representation of the type. For ...