Skip to main content

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.

Filter by
Sorted by
Tagged with
3 votes
2 answers
254 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 ...
lamont's user avatar
  • 139
8 votes
1 answer
298 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 ...
Corbin's user avatar
  • 851
6 votes
2 answers
430 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 ...
user23013's user avatar
  • 2,390
1 vote
2 answers
301 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 ...
Delfin's user avatar
  • 159
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 ...
tinlyx's user avatar
  • 427
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 ...
ceving's user avatar
  • 366
29 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: ...
MaiaVictor's user avatar
5 votes
2 answers
730 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 ...
alephalpha's user avatar
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), ...
apropos's user avatar
  • 1,012
15 votes
3 answers
803 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 ...
blueberry's user avatar
  • 2,455
3 votes
1 answer
258 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 ...
Jw C's user avatar
  • 231
0 votes
1 answer
94 views

What is the object translating part of a monadic endofunctor? [closed]

A monad is an endofunctor $T:C\rightarrow C$ with natural transformations $\eta:id_C\rightarrow T$ and $\mu:T^2\rightarrow T$. Being natural transformations mean that $$T(f)\circ \eta_A = \eta_B\circ ...
Gergely's user avatar
  • 353
3 votes
1 answer
232 views

Call-by-value: Left-to-right vs right-to-left

There are three standard evaluation strategies for the lambda calculus: Call-by-value (CBV) Call-by-name Call-by-need There are two variants of CBV that differ on how they behave with respect to ...
user76284's user avatar
  • 159
8 votes
1 answer
416 views

Possible ways for a system interface in a lazy LC language?

I'm writing a backend for lazy lambda calculus. Now I'm curious about how it could interface with the system. As an experiment, I managed to write READ and WRITE primitives, each of which does the ...
Bubbler's user avatar
  • 713
1 vote
1 answer
235 views

How to avoid hidden performance problems in functional interfaces?

Swift has a protocol Sequence<Element>, which is used to support for-in loops. It has ...
Bbrk24's user avatar
  • 8,937
3 votes
1 answer
71 views

Quantified variables without case-based analysis in traits

In almost every functional language I know of, quantified type variables are identified using case: ...
blueberry's user avatar
  • 2,455
10 votes
1 answer
262 views

Why don't pure functional languages have object identity?

In object-oriented languages, there is typically a notion of object identity which is distinct from object value, such that two objects can have the same values but different identities. For example, ...
kaya3's user avatar
  • 19.1k
10 votes
1 answer
319 views

What are the disadvantages of lazy languages?

I understand there are some advantages of lazy languages like Haskell. For example, one can easily write/use an infinite list without worrying about it being evaluated eagerly. I heard there are other ...
tinlyx's user avatar
  • 427
5 votes
1 answer
173 views

Which functions should a compiler cache outputs for?

Because a bare function object might not have constant time complexity, and because the function object might be called with the same argument repeatedly, I thought it might be good to cache its ...
Dannyu NDos's user avatar
14 votes
3 answers
448 views

What are the pros and cons of automatically curried functions?

In several functional languages like Haskell and OCaml, functions are automatically curried. This means that a function taking two arguments (lambda x, y: x + y) is ...
naffetS's user avatar
  • 1,047
11 votes
2 answers
239 views

Capturing from outer stack to lambda in a stack-based language?

I'm working on a stack based lang that has "wraps", essentially lambdas, that by default run with an isolated stack (though some commands can push things to a wrap's stack, effectively ...
RubenVerg's user avatar
  • 1,422
11 votes
1 answer
224 views

Runtime/Backend for a lazy, pure functional, lambda-calculus-based language?

I'm thinking of writing a toy language based on lambda calculus. I want it to be lazily evaluated. I/O is not a concern for now; main will be a pure function that ...
Bubbler's user avatar
  • 713