Skip to main content

Questions tagged [fold]

Reducing a sequence of terms to a single term.

2 votes
2 answers
163 views

Affect a repetition of an argument N times (for array construction)

Consider the following (C++20) function (from the solution to this StackOverflow question): ...
einpoklum's user avatar
  • 2,099
1 vote
1 answer
94 views

Build a fixed-length vector from a recursive factory function

I need a function of type forall (n :: Nat). RandomGen q => q -> Vec n q. Obviously this is possible to do (correctly, don't just ...
ShapeOfMatter's user avatar
5 votes
1 answer
1k views

fold expressions using a function recursively

I have written an accumulate function similar to std::accumulate that works on a std::array. The goal is to remove the loop using fold expressions. This code currently works in c++17: ...
RadAd's user avatar
  • 153
1 vote
2 answers
547 views

Implementations of unzip in Racket

I've been practicing my folds and tail-call recursive programming, and I wanted to work on unzip for the general case as opposed to just pairs. This was very easy ...
BrainFRZ's user avatar
  • 841