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
6 votes
3 answers

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
  • 356
29 votes
5 answers

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

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

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
  • 900
10 votes
1 answer

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
  • 1,582
3 votes
1 answer

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
  • 121
0 votes
1 answer

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
  • 303
3 votes
1 answer

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
7 votes
1 answer

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
  • 683
1 vote
1 answer

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,563
3 votes
1 answer

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
  • 1,582
10 votes
1 answer

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
  • 16.3k
10 votes
1 answer

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
  • 335
5 votes
1 answer

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
13 votes
3 answers

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
  • 989
11 votes
2 answers

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,287
10 votes
1 answer

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
  • 683