Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.

Questions tagged [functional-programming]

This tag is for challenges related to the functional programming paradigm.

Filter by
Sorted by
Tagged with
0 votes
4 answers
336 views

A monad is a type that wraps another type, that represents the available operations on the wrapped type. Monads have the following associated operations, where M is ...
bigyihsuan's user avatar
  • 11.4k
10 votes
14 answers
2k views

Task I need a function that accept string and return a function f1. That f1 function should also accept string and return a <...
talex's user avatar
  • 927
24 votes
19 answers
2k views

The golfing language Jelly has a built-in ƭ called "tie", that cycles through a list of functions every time it's called. For example, ...
emanresu A's user avatar
  • 46.2k
3 votes
1 answer
603 views

The goal of this challenge is to compare how well different programming languages support functional programming, by seeing how much code it takes to implement BLC8, the simplest functional ...
John Tromp's user avatar
  • 1,461
12 votes
3 answers
1k views

In this programming-puzzle, your goal is to write the following function in JavaScript, using (essentially) point-free (tacit) programming: (f) => void(f()) ...
rydwolf's user avatar
  • 19.3k
10 votes
6 answers
775 views

A fixed-point combinator is a higher order function \$\mathrm{fix}\$ that returns the fixed point of its argument function. If the function \$f\$ has one or more fixed points, then $$\mathrm{fix} f=f(\...
Legendary Wizard's user avatar
28 votes
19 answers
3k views

Ruby has a strange operator, .., called flip-flop (not to be confused with the range operator, which looks the same). Used in a loop, flip-flop takes two conditions ...
Jordan's user avatar
  • 11.9k
16 votes
14 answers
2k views

The persistence of a number \$x = d_1d_2d_3...d_n\$, with \$d_1 \ne 0\$, under some function \$f : \mathbb N_0 \times \mathbb N_0 \to \mathbb N_0\$ is defined as the number of applications of \$f\$ to ...
caird coinheringaahing's user avatar
11 votes
2 answers
928 views

Curry is the Language of the Month this month and some users are starting to get into it, so let's get some tips together. Haskell and Curry are similar in a lot of ways and a lot of tips for Haskell ...
Wheat Wizard's user avatar
  • 103k
27 votes
44 answers
3k views

The \$\text{argwhere}\$ function takes a list of values and a predicate/boolean function as arguments and returns a list of indices where the predicate function returns true in the input list. For ...
chunes's user avatar
  • 27.8k
18 votes
9 answers
1k views

Background K functions have a feature called projection, which is essentially partial application of values to a function. The syntax for projections is a natural extension of the regular function ...
Bubbler's user avatar
  • 79.3k
7 votes
4 answers
348 views

Background Supplementary reading 1, Supplementary reading 2 Linear lambda calculus is a limited form of lambda calculus, where every bound variable must be used exactly once. For example, ...
Bubbler's user avatar
  • 79.3k
19 votes
16 answers
2k views

Task Haskell's and Scala's standard libraries have an unfold function that builds a list from an initial state s and a function <...
user's user avatar
  • 457
17 votes
2 answers
1k views

Background Lambda calculus is a model of computation using lambda terms. A variable \$x\$ is a lambda term. If \$E\$ is a lambda term, the lambda abstraction \$\lambda x. E\$ is a lambda term. If \$...
Bubbler's user avatar
  • 79.3k
23 votes
46 answers
3k views

Think of cleave as the conceptual inverse of map. If map applies a function to each number in a list... map([1, 2, 3], x -> x * 5) -> ...
chunes's user avatar
  • 27.8k
9 votes
3 answers
525 views

Background The fixed-point combinator \$\textsf{fix}\$ is a higher-order function that computes the fixed point of the given function. $$\textsf{fix}\ f = f\ (\textsf{fix}\ f)$$ In terms of ...
Bubbler's user avatar
  • 79.3k
15 votes
10 answers
1k views

Background Combinatory logic is a system where a term is written using a finite set of combinators and function application between terms, and reduction rules are defined for each combinator. The well-...
Bubbler's user avatar
  • 79.3k
18 votes
2 answers
491 views

Background Combinatory logic is a system where a term is written using a finite set of combinators and function application between terms, and reduction rules are defined for each combinator. The well-...
Bubbler's user avatar
  • 79.3k
26 votes
39 answers
2k views

Given: a blackbox function \$f : \mathbb N \to \mathbb N\$, a list of positive integers \$L\$, and a list of indices \$I\$, apply \$f(x)\$ to the elements of \$L\$ at the indices specified in \$I\$. ...
caird coinheringaahing's user avatar
37 votes
52 answers
3k views

Over is a higher-order function in multiple languages such as APL (). It takes 2 functions and 2 values as arguments, applies the first function to both values, ...
caird coinheringaahing's user avatar
25 votes
43 answers
4k views

zipwith is a functional construct that takes three arguments: one binary function and two lists of the same length, and returns a single list where each element is ...
caird coinheringaahing's user avatar
23 votes
18 answers
5k views

I don't like curry. Help me reverse the effects of this evil question - Make me some curry - by uncurrying functions. Task Given a blackbox curried function, output its uncurried equivalent. The ...
user's user avatar
  • 457
15 votes
9 answers
2k views

Church Subtraction Lambda calculus has always been a fascination of mine and the emergent behaviors of passing functions into each other is delightfully complex. Church numerals are representations ...
Ryan Schaefer's user avatar
36 votes
20 answers
8k views

Church booleans A Church boolean is a function that returns x for true and y for false where ...
Ryan Schaefer's user avatar
5 votes
2 answers
1k views

This challenge is about Haskell point-free style polynomial functions. Although you don't need to know Haskell language to do this challenge, Haskellers might have an advantage here. Point-free ...
Damien's user avatar
  • 2,467
22 votes
14 answers
2k views

The Dirichlet convolution is a special kind of convolution that appears as a very useful tool in number theory. It operates on the set of arithmetic functions. Challenge Given two arithmetic ...
flawr's user avatar
  • 44.1k
1 vote
2 answers
328 views

Introduction I have some JavaScript code that uses Array.prototype.map to map an array of functions fns to their return values: ...
Rory O'Kane's user avatar
18 votes
15 answers
2k views

Motivation: Sometimes certain items in a list don't count towards your totals. For example, counting plane passengers in rows, where babies sit on a parent's laps. Challenge: write a program to split ...
Tom Viner's user avatar
  • 443
29 votes
23 answers
4k views

Having a function f that takes arguments x1, x2, …, xn                         &...
ბიმო's user avatar
42 votes
81 answers
9k views

Using your language of choice, write a function that takes a variable number of arguments and returns the number of arguments it was called with. Specifics: Your language needs to support variadic ...
Glenn Smith's user avatar
18 votes
20 answers
1k views

Recently, my reputation was 25,121. I noticed that each digit grouping (i.e. the numbers separated by commas) was a perfect square. Your challenge is, given a non-...
Conor O'Brien's user avatar
23 votes
28 answers
2k views

Inspiration. Given (by any means): A two-argument (or single argument consisting of a two-element list) black box function, f: ℤ+ × ℤ+ → ℤ+ (input and output are 1,...
Adám's user avatar
  • 31.8k
18 votes
4 answers
1k views

What is the shortest way we can express the function f(a,b)(c,d)=(a+c,b+d) in point-free notation? pointfree.io gives us ...
Wheat Wizard's user avatar
  • 103k
25 votes
32 answers
3k views

Given an integer \$x_1\$ and some black box function \$f: ℤ → ℤ\$ find a fixed point of \$f\$ in the sequence defined by \$x_{k+1} := f(x_k)\$. Details A value \$x\$ is said to be a fixed point of \$...
flawr's user avatar
  • 44.1k
16 votes
3 answers
1k views

Are there any functional programming languages designed for code golfing? I know that golfscript and CJam fulfill the same category for stack based, but I couldn't find a functional code golfing ...
Christopher King's user avatar
58 votes
45 answers
5k views

Write a function, f, that takes in a positive integer and returns a function. The new function returned should be identical to f...
Eugene D. Gubenkov's user avatar
22 votes
1 answer
2k views

The λ-calculus, or lambda calculus, is a logical system based on anonymous functions. For example, this a λ-expression: λf.(λx.xx)(λx.f(xx)) However, for the ...
Esolanging Fruit's user avatar
37 votes
96 answers
5k views

Introduction and Credit Today without a fancy prelude: Please implement takewhile. A variation of this (on a non-trivial data structure) was an assignment at my ...
SEJPM's user avatar
  • 3,463
25 votes
15 answers
2k views

Challenge Find an expression, at most 100 bytes long, with the longest type signature. Rules Any statically typed language with type inference is allowed The type must be non-ambiguous, but otherwise ...
Michael Klein's user avatar
0 votes
3 answers
222 views

map is a very basic yet important function in functional programming. All FP programming languages have it built-in but it is always fun to see how shortly you can ...
Caridorc's user avatar
  • 2,406
25 votes
11 answers
1k views

Your company is just getting started on a project, and for the first time you decided to go use a functional programming code-style. However your boss is really diffident and doesn't want to use built-...
WizardOfMenlo's user avatar
8 votes
6 answers
2k views

Background (F#) Let there be trees: type Tree<'T> = Node of 'T * Tree<'T> list Now lets fold them nicely with a function called... ...
Good Night Nerd Pride's user avatar
11 votes
4 answers
1k views

EDIT: As some of you suspected, there was a bug in the official interpreter: the order of composition in . was reversed. I had two versions of the interpreter, and ...
Zgarb's user avatar
  • 43.2k
-2 votes
3 answers
314 views

Develop a program which takes two arrays of decimal numbers, and compare the sum of whole numbers only and the decimal part. If the sums of the whole numbers are the same, and the decimal parts of ...
andyra42's user avatar
9 votes
5 answers
437 views

The Haskell function biSp has type signature ...
dspyz's user avatar
  • 943
21 votes
3 answers
3k views

I got the following question at a test: Write a function f with the following type a -> b -> (a -> b). ...
Radu Stoenescu's user avatar
5 votes
12 answers
620 views

You are given two functions \$g(x)\$ and \$h(x)\$, each of which takes an integer \$x\$ and returns the number \$ax + b\$ (where \$a\$ and \$b\$ are integers defined in the function). Your task is to ...
Joe Z.'s user avatar
  • 35.4k
13 votes
9 answers
791 views

Write a fixed point combinator in as few characters as possible, in the language of your choice. free form (i.e., whatever's shortest): whole program, actual function, code snippet you may not use ...
J B's user avatar
  • 10.1k