Questions tagged [recursion-schemes]

Recursion schemes are reusable patterns for making recursive calls. They include catamorphisms and anamorphisms. This tag covers both the general concept, and the Haskell library of the same name.

Recursion schemes are reusable patterns for making recursive calls. They include catamorphisms and anamorphisms. This tag covers both the general concept, and the Haskell library of the same name which implements them using higher-order functions and type families.

cf. the recursion-schemes package.

See also

107 questions
1
vote
1 answer

Lattice paths algorithm using recursion schemes

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 from a collection of interview…
cocorudeboy
  • 119
  • 5
1
vote
1 answer

How can I avoid explicit recursion in this case?

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 a) -- why "Could not deduce (Foldable t0) arising from a use of…
1
vote
1 answer

How do I write a CV-Coalgebra in Idris2?

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 CoAttrWithoutAutomatic (f : Type -> Type) where …
nnnmmm
  • 7,964
  • 4
  • 22
  • 41
1
vote
1 answer

Morphism where the algebra receives the item's position

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 ["foo", "bar", "qux"] into the string "foo, bar,…
P Varga
  • 19,174
  • 12
  • 70
  • 108
1
vote
1 answer

Recursion schemes with mutually recursive types in Scala

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) extends Expression sealed trait…
kthompson
  • 803
  • 6
  • 16
1
vote
2 answers

A recursion scheme from Int -> Int?

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 structure. [Int] -> [Int] or [Int] ->…
Conor Quinn
  • 529
  • 4
  • 13
1
vote
4 answers

Generate lexicographic series efficiently in Python

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 4-digit numbers with sum = 3 then I have a series…
1
vote
1 answer

Exhibiting the relationship between hylo and hyloM

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, Monad m) => (g b -> m b) -> (a -> m (g a)) -> a -> m b hyloM f g = h…
Julian Birch
  • 2,605
  • 1
  • 21
  • 36
1
vote
1 answer

Repetitions as an Hylomorphism

So I've been trying to convert this Haskell function thats checks if a list doesn't have any repetitions into an Hylomorphism, but there's something odd about it. valid :: [a] -> Bool valid [] = True valid (h:t) = if (not (elem h t)) then valid t…
1
vote
1 answer

An example for chronomorphism

I don't understand how can I create some example with chronomorphism. I know about hylomorphism (cata, ana) also I know about histo and futu. But I don't realize some example for chronomorphism (maybe some behavior as in Tardis monad). Also related…
xgrommx
  • 461
  • 3
  • 15
1
vote
1 answer

Order of evaluation for cataM

In the following code, how is it possible to have cataM traverse the tree top-down (and not bottom-up as it is the case currently) ? I guess I should implement foldMap differently but how to process the branch node itself before the children since…
z1naOK9nu8iY5A
  • 903
  • 7
  • 22
1
vote
0 answers

Use cata with Sum of functors

I'm playing with Data.Fix and Data.Functor.Sum, and trying to use cata with sum of functors, then ran into an issue that code didn't type check. But I'm not sure how I can make it type check. Here is the code. {-# LANGUAGE DeriveFunctor,…
snak
  • 6,483
  • 3
  • 23
  • 33
0
votes
0 answers

ERR_UNKNOWN_URL_SCHEME in WebView flutter plus

I'm trying to build a mobile app from local HTML, CSS and JS files. using flutter plugin (webView flutter plus). There is contact links in my index.html page such as: Click here to call
0
votes
1 answer

Scheme programming, going through a list and making everything inside a list

homework question: (diginlist '(4 5 3 2 8)) is supposed to return (4(5(3)2)8) (define(removelast L) (if(null?(cdr L)) '() (cons(car L) removelast(cdr L)))) (define(last L) (if(null?(cdr L)) (car L) (last(cdr L)))) (define(diginlist L) …
muayad925
  • 61
  • 3
-1
votes
1 answer

How to solve this indirect recursion error?

#include #include using namespace std; void funB(int n){ if (n>1){ cout<0){ cout<