Questions tagged [fold]

Reducing a sequence of terms to a single term.

Filter by
Sorted by
Tagged with
0 votes
0 answers
53 views

Early exist fold implementations in F# with a high degree of similarity

I've been writing a bunch of helper functions lately, all revolving around the concept of an early exit fold (which is a bit like unfold, i.e. you can control when the looping ends but you pass a list ...
user avatar
  • 1,101
1 vote
1 answer
45 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 ...
user avatar
5 votes
1 answer
435 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: ...
user avatar
  • 53
1 vote
1 answer
392 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 ...
user avatar
  • 819