Skip to main content
Stack Overflow for Teams is now Stack Internal: See how we’re powering the human intelligence layer of enterprise AI. Read more >
Filter by
Sorted by
Tagged with
1 vote
1 answer
76 views

I need to extend the definition of left scan to Cofree structures, to accumulate annotations from the root of an annotated AST to the leaves, however I don't understand why my naive implementation ...
ocramz's user avatar
  • 841
4 votes
2 answers
172 views

I'm learning recursion patterns, but I can't figure out the usefulness of futumorphism and histomorphism. The couple of Scala examples I found look very unconvincing. I also found Haskell examples, ...
Sergey Sviridov's user avatar
-1 votes
1 answer
96 views

I am learning about different recursive approaches for reversing a linked list in C++. I have implemented both head and tail recursion methods, but I'm unsure about their differences and which one is ...
Aman maurya's user avatar
2 votes
1 answer
71 views

I have this data structure, that I'd like to introduce recursion schemes to in order to attach metadata to nodes: sealed trait Schema[A] extends Product, Serializable sealed trait Collection[A] ...
Taig's user avatar
  • 7,408
2 votes
1 answer
115 views

This is a definition of foldr and foldl in terms of foldr: foldr :: (a -> b -> b) -> b -> [a] -> b foldr f z [] = z foldr f z (x:xs) = f x (foldr f z xs) foldl :: (a -> b -> a)...
cocorudeboy's user avatar
1 vote
1 answer
103 views

I need to model a computation task and some sub-tasks depend on it: First I run a task, if it fails then it's over. If it succeeds then run a bunch of sub-tasks(zero or many), any of them can fail or ...
Annihilus's user avatar
5 votes
1 answer
267 views

Is it possible to memoize a recursion scheme? If so, how would you? For example, the following uses anamophism and catamorphism newtype Fix f = In (f (Fix f)) deriving instance (Eq (f (Fix f))) => ...
cocorudeboy's user avatar
1 vote
1 answer
158 views

I'm trying to use paramorphisms and apomorhisms (in haskell): -- Fixed point of a Functor newtype Fix f = In (f (Fix f)) ...
cocorudeboy's user avatar
3 votes
1 answer
153 views

I've got anamorphism defined as follows: -- Fixed point of a Functor newtype Fix f = In (f (Fix f)) deriving instance (Eq (f (Fix f))) => Eq (Fix f) deriving instance (Ord (f (Fix f))) => Ord (...
cocorudeboy's user avatar
1 vote
1 answer
186 views

I'm playing around with some recursion schemes, namely catamorphisms and anamorphisms, and would like to try to implement a solution to the lattice paths algorithm as described below using them (taken ...
cocorudeboy's user avatar
2 votes
1 answer
136 views

From this talk about nanopass compilers in 2017 (https://github.com/sellout/recursion-scheme-talk/blob/master/nanopass-compiler-talk.org) I found the code snippet below. In this code snipped, I see ...
Charles Josephs's user avatar
2 votes
1 answer
175 views

I'm trying to implement a binary search tree (or set) using fixed points of functors. I've defined my fixed point as follows: newtype Fix f = In (f (Fix f)) out :: Fix f -> f (Fix f) out (In f)...
Conor Quinn's user avatar
3 votes
2 answers
258 views

I have this AST data structure data AST = Integer Int | Let String AST AST | Plus AST AST | Minus AST AST | Times AST AST | Variable String | ...
Ace shinigami's user avatar
1 vote
1 answer
194 views

I wound up with this skeleton: f :: (Monad m) => b -> m () f x = traverse_ (f . g x) =<< h x -- how avoid explicit recursion? g :: b -> a -> b -- h :: (Foldable t) => b -> m (t ...
user1441998's user avatar
8 votes
1 answer
1k views

I'm trying to get more proficient with recursion schemes as they have so far been really helpful for turning gnarly explicit recursion code into something less spike-y. One of the other tools I tend ...
Ace shinigami's user avatar
8 votes
0 answers
192 views

I'm exploring recursion-schemes recently and want to find some use cases for histomorphism - for which I think Catalan numbers could be a fun one (I'm aware there are better ways to implement Catalan ...
Javran's user avatar
  • 3,431
6 votes
2 answers
213 views

Various recursion scheme boil down to specific instantiation of refold refold :: Functor s => (s b -> b) -> (a -> s a) -> a -> b refold f g = go where go a = f (fmap go (g a)) What ...
nicolas's user avatar
  • 9,845
10 votes
1 answer
378 views

I started with this type for leaf-valued trees with labeled nodes: type Label = String data Tree a = Leaf Label a | Branch Label [Tree a] I have some folds I'd like to write over this ...
amalloy's user avatar
  • 93k
3 votes
1 answer
285 views

I came across a nice post on SO by @amalloy while looking for hylomorhism examples, that illustrate recursion scheme (RS) usage with useful discussion and full implementation: {-# LANGUAGE ...
maplike's user avatar
  • 31
4 votes
3 answers
235 views

I implemented Euclid's algorithm in the following way at first. euclid x 0 = x euclid x y = euclid y (x `mod` y) The algorithm is tail-recursion, and I expect that it can be intuitively written with ...
いとうかつとし's user avatar
4 votes
3 answers
605 views

I'm trying to understand histomorphisms from this blog on recursion schemes. I'm facing a problem when I'm running the example to solve the change making problem as mentioned in the blog. Change ...
twitu's user avatar
  • 655
-2 votes
2 answers
344 views

Im trying to make a non-tail recursive function returns the last element of a list without using reverse, map, iteration, mutation of any sort (built in or user-built). So far I have successfully made ...
Linh Duong's user avatar
4 votes
0 answers
161 views

One of my favourite things about the recursion schemes in Haskell are the generalised morphisms (gcata etc.) that allow interleaving (co-)monadic computations with recursion, using a monad transformer ...
Luciano's user avatar
  • 2,428
5 votes
1 answer
290 views

My problem is how to combine the recursive, F-algebra-style recursive type definitions, with monadic/applicative-style parsers, in way that would scale to a realistic programming language. I have ...
Matei's user avatar
  • 152
-5 votes
1 answer
228 views

I have this algorithm: static int findMaxRec(int[] w, int[] v, int W, int n) { int max = int.MinValue; int res; for (int i = 0; i < n; i++) { if (w[i] <= W) { ...
vytaute's user avatar
  • 1,548
-1 votes
1 answer
165 views

#include <iostream> #include <stdio.h> using namespace std; void funB(int n){ if (n>1){ cout<<n<<" "; funA(n/2); } } void funA(int m) { if (m>0)...
Yash Ingle's user avatar
2 votes
2 answers
287 views

I'm interested in a higher-order way (recursion scheme) to write recursive code in which there might be dependencies between recursive calls. As a simplified example, consider a function that ...
trpnd's user avatar
  • 474
2 votes
1 answer
146 views

By co-recursion I mean unfolding a tree, such as with anamorphism from Ed Kmett's recursion-schemes By re-combining trees I mean graphs that share structure. For example, a binomial option pricing ...
Luciano's user avatar
  • 2,428
1 vote
1 answer
62 views

In Haskell, I can write data CoAttr f a = Automatic a | Manual (f (CoAttr f a)) but Idris doesn't seem to allow such fix-point types with data. They do work with record, i.e. I can write record ...
nnnmmm's user avatar
  • 8,934
2 votes
0 answers
138 views

The well-known Church encoding of natural numbers can be generalized to use an arbitrary functor F. The result is the type, call it C, defined by data C = Cfix { run :: forall r. (F r -> r) -> ...
winitzki's user avatar
  • 3,357
1 vote
1 answer
57 views

Which one is the appropriate morphism (recursion scheme) to use when the given item's position (index, or path) is required in the transformer function? A simple example would be transforming a list [&...
P Varga's user avatar
  • 20.4k
1 vote
1 answer
298 views

Given the following data types: sealed trait Expression final case class Add(a: Expression, b: Expression) extends Expression final case class Block(statements: List[Statement], result: Expression) ...
kthompson's user avatar
  • 892
5 votes
0 answers
251 views

I'm trying to build the following recursion scheme: {-# LANGUAGE DeriveFunctor #-} import Data.Functor.Foldable import Control.Comonad import Control.Comonad.Cofree data Term a = Str String | Array [...
Nastya Koroleva's user avatar
9 votes
1 answer
423 views

In the recursion-schemes package the following types are defined: newtype Fix f = Fix (f (Fix f)) newtype Mu f = Mu (forall a. (f a -> a) -> a) Are they isomorphic? If so, how do you prove it?
marcosh's user avatar
  • 9,038
2 votes
0 answers
140 views

I've recently looked up some guides on recursion schemes in Haskell, however most articles don't go much beyond implementing the basic infrastructure required for these concepts. Given a recursive ...
string_loginUsername's user avatar
6 votes
1 answer
223 views

In recursion schemes, how can I construct something with type definition like (Recursive t, CoRecursive t) -> t -> ? -> t I try to use recursion-schemes to update nodes. Taking list as an ...
Zhu Jinxuan's user avatar
6 votes
2 answers
352 views

Consider this code: import Data.Maybe (fromMaybe) data MyStructure = Foo Int | Bar String MyStructure | Baz MyStructure MyStructure | Qux Bool Bool MyStructure MyStructure deriving(Eq,Show) ...
Joseph Sible-Reinstate Monica's user avatar
6 votes
1 answer
299 views

I'd like to see a Coq version of the Bananas, Lenses, etc. They are built up in the excellent series of blog posts at sumtypeofway Introduction to Recursion schemes However, the blog post is in ...
larsr's user avatar
  • 5,898
2 votes
1 answer
564 views

Can we define a recursion scheme (without losing any of their generality) that constructs the value top-down, instead of bottom-up? This would be quite helpful as I've seen plenty of times where the ...
Welperooni's user avatar
7 votes
2 answers
435 views

I recently read about recursion schemes where catamorphisms are described as analogous to generalized foldr. Is is possible to write an instance of Foldable (via either foldr or foldMap) in terms of ...
Michael Thomas's user avatar
3 votes
2 answers
183 views

I have a variadic lifting function that allows for flat monadic chains without deeply nested function composition: const varArgs = f => { const go = args => Object.defineProperties( ...
user avatar
4 votes
1 answer
201 views

I've been trying to translate this recursive Haskell implementation of a futumorphism specialized to Lists futuL :: (a -> Maybe (b, ([b], Maybe a))) -> a -> [b] futuL f x = case f x of ...
user avatar
2 votes
2 answers
606 views

I am learning recursion schemes and it has proven very helpful to me to implement them specific to the list type. However, I got stuck on apomorphisms. Here is an implementation of tails in terms of ...
user avatar
5 votes
3 answers
365 views

Is there a name for a recursion scheme that's like a catamorphism, but that allows peeking at the final result while it's still running? Here's a slighly contrived example: toPercents :: Floating a =&...
Joseph Sible-Reinstate Monica's user avatar
1 vote
2 answers
379 views

The foldr identity is foldr (:) [] More generally, with folds you can either destroy structure and end up with a summary value or inject structure in such a way that you end up with the same output ...
Conor Quinn's user avatar
3 votes
1 answer
2k views

I am currently learning folds in the sense of structural recursion/catamorphisms. I implemented power and factorial using a fold for natural numbers. Please note that I barely know Haskell, so the ...
user avatar
0 votes
4 answers
807 views

I want to generate a lexicographic series of numbers such that for each number the sum of digits is a given constant. It is somewhat similar to 'subset sum problem'. For example if I wish to generate ...
Aman_X's user avatar
  • 77
3 votes
1 answer
414 views

Looking around, I noticed that recursion schemes are quite a general concept and I wanted to learn by experiencing it first hand. So I started implementing a minimax algorithm for TicTacToe. Here is a ...
WorldSEnder's user avatar
  • 5,106
1 vote
1 answer
106 views

I'm told the following functions are equivalent in power hylo :: Functor f => (f b -> b) -> (a -> f a) -> a -> b hylo f g = h where h = f . fmap h . g hyloM :: (Traversable g, ...
Julian Birch's user avatar
  • 2,846
7 votes
3 answers
717 views

I feel like understanding the abstract concept of fixed point of a functor, however, I am still struggling to figure out the exact implementation of it and its catamorphism in Haskell. For example, ...
learnereveryday's user avatar