Skip to main content
Filter by
Sorted by
Tagged with
6 votes
1 answer
90 views

I am interested in methods for serializing and deserializing a binary tree in breadth-first order. The first part, serialization, is equivalent to performing a levelorder traversal where we preserve ...
Brendan Langfield's user avatar
2 votes
1 answer
111 views

To phrase the question differently: if we were to remove termination-checking and the guardedness condition on uses of inductive and coinductive data types, respectively, would there cease to be a ...
Max Heiber's user avatar
  • 15.8k
11 votes
1 answer
2k views

This is a corecursive algorithm, because with each iteration it calls itself on data that is greater then what it had before: iterate f x = x : iterate f (f x) It is similar to tail recursion ...
user avatar
1 vote
1 answer
243 views

Corecursion means calling oneself on data at each iteration that is greater than or equal to what one had before. Corecursion works on codata, which are recursively defined values. Unfortunately, ...
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
4 votes
1 answer
421 views

I would like to solve the following dynamic programming problem via corecursion in Prolog. But I am stuck in doing the breadth first search, that I would like to implement, in a correcursive fashion: ...
user avatar
1 vote
2 answers
854 views

I am trying to write a recursive function the evaluate for n 3(2+1)+4(3+2+1)+...+(n+1)(n+...+2+1) I know that in general we need to write it as induction the result for the base case let say n=1 and ...
gbox's user avatar
  • 829
2 votes
1 answer
187 views

I'd like to write down some definitions (and prove some lemmas!) about paths in a graph. Let's say that the graph is given implicitly by a relation of type 'a => 'a => bool. To talk about a ...
Rupert Swarbrick's user avatar
2 votes
1 answer
138 views

I've been trying out coinductive types and decided to define coinductive versions of the natural numbers and the vectors (lists with their size in the type). I defined them and the infinite number as ...
Gabriel Barreto's user avatar
2 votes
2 answers
569 views

Using cata I can fold an AST to a result. With Cofree I can store additional annotations on the AST. How can I take an AST and return an annotated AST with the results at each step of the way? alg :: ...
user47376's user avatar
  • 2,283
6 votes
1 answer
197 views

I want to write Foldable.toList for a non-empty rose tree using an anamorphism, but it seems impossible to extract the last element: import Data.Functor.Foldable data RoseTree a = RoseNode a [...
nponeccop's user avatar
  • 13.7k
2 votes
1 answer
1k views

.NET Reactive Extensions has a neat method to generate sequences using corecursion which is called Observable.Generate. Is there analogues method in RxJava that allows data generation via ...
dkunin's user avatar
  • 60
3 votes
1 answer
156 views

I wrote a function in Racket to produce something similar to the following fractal. (define CUT-OFF 5) (define CIRCLE-MODE "outline") (define (circle-fractal size colour) (local [(define full-...
user avatar
0 votes
1 answer
54 views

This (trimmed out) corecursive function definition in Isabelle primcorec tree :: "'form fset ⇒ 'vertex ⇒ 'preform ⇒ (('form fset × 'form), ('rule × 'preform) NatRule) dtree" where "tree Γ v p = (...
Joachim Breitner's user avatar
0 votes
2 answers
205 views

I need help trying to find where to place the print statements in each function (alpha_count and sum_digits) so that they will only print once (at the end of the program). Ex. Number of characters: 8 ...
Felicia's user avatar
  • 33
7 votes
1 answer
822 views

I'm playing around with the language to start learning and I am puzzled beyond my wits about how a recursive definition works. For example, let's take the sequence of the Triangular numbers (TN n = ...
Diego Martinoia's user avatar
6 votes
5 answers
2k views

I'm trying to create an Observable where each item is produced via an asynchronous task. The next item should be produced via an async call on the result of the previous item (co-recursion). In "...
csauve's user avatar
  • 6,343
3 votes
0 answers
230 views

Wikipedia's discussion of recursion indicates that generatively recursive functions "can often be interpreted as corecursive functions" (emphasis mine) while Wikipedia's discussion of corecursion ...
Ben Gribaudo's user avatar
  • 5,177
8 votes
3 answers
493 views

I'm working on a C++ project that requires frequent interaction with a tree structure, which means lots of recursive functions, and I'm looking for ways to improve the code. I came across corecursion ...
Logical Fallacy's user avatar
1 vote
1 answer
120 views

I’m doing my first experiments with codatatype, but I’m stuck rather early. I started with this definition of a branching, possibly infinite tree: codatatype (lset: 'a) ltree = Node (lnext : "'a ⇒ 'a ...
Joachim Breitner's user avatar
1 vote
1 answer
138 views

I know in python classes and functions can be created at runtime using type and lambda respectively, but can generators be created at runtime? Example: keyword, condition, action, yield lambda x,a:...
Hovestar's user avatar
  • 1,627
12 votes
1 answer
188 views

I've defined the infinite list of infinite lists pathCounts and the infinite list of finite lists pathCounts': import Data.Function (fix) nextRow xs = fix $ \ys -> zipWith (+) xs (0:ys) ...
rampion's user avatar
  • 89.6k
11 votes
2 answers
755 views

I implemented a broken filter function using an anamorphism from recursion-schemes Hackage library: import Data.Functor.Foldable xfilter :: (a -> Bool) -> [a] -> [a] xfilter f = ana $ ...
nponeccop's user avatar
  • 13.7k