23 questions
6
votes
1
answer
90
views
Is there a simple recursive analogue of this breadth-first binary tree deserialization function in Haskell?
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 ...
2
votes
1
answer
111
views
Is the only difference between Inductive and CoInductive the well-formedness checks on their uses (in Coq)?
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 ...
11
votes
1
answer
2k
views
What constitutes codata in the context of programming?
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 ...
1
vote
1
answer
243
views
How to encode corecursion/codata in a strictly evaluated setting?
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, ...
4
votes
1
answer
201
views
Express a futumorphism specialized to lists as an imperative loop
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
...
4
votes
1
answer
421
views
Solve dynamic programming in Prolog via corecursion
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:
...
1
vote
2
answers
854
views
Recursive Function With Increasing Values
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 ...
2
votes
1
answer
187
views
Reasoning about the entirety of a codatatype in Isabelle/HOL
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 ...
2
votes
1
answer
138
views
Coinduction on Coq, type mismatch
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 ...
2
votes
2
answers
569
views
Haskell Recursion Schemes: Label the tree with intermediate results
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 :: ...
6
votes
1
answer
197
views
Unfolding non-empty structures to lists
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 [...
2
votes
1
answer
1k
views
Observable.Generate in RxJava?
.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 ...
3
votes
1
answer
156
views
Corecursion Doesn't Terminate After Small Change
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-...
0
votes
1
answer
54
views
Unexpected corecursive call
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 =
(...
0
votes
2
answers
205
views
How to use corecursion in c?
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
...
7
votes
1
answer
822
views
How does (co)recursive definition work in Haskell?
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 = ...
6
votes
5
answers
2k
views
Observable from chained Tasks
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 "...
3
votes
0
answers
230
views
Generative Recursion vs. Corecursion
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 ...
8
votes
3
answers
493
views
How to accomplish corecursion in C++?
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 ...
1
vote
1
answer
120
views
"invalid map function" when defining a corecursive tree
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 ...
1
vote
1
answer
138
views
Python: Create Generators at Runtime
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:...
12
votes
1
answer
188
views
Why does :p freeze in GHCi when I give it this corecursive value?
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)
...
11
votes
2
answers
755
views
List filter using an anamorphism
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 $ ...