You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
dataTreea=Fork (Treea) a (Treea) | NilderivingShowfoldTree::Treea-> (b->a->b->c) ->c->Hyperbc
foldTree t f n = foldTree'
(\l x r ->Hyper$\k -> f (invoke k l) x (invoke k r))
(pure n)
t where
foldTree' f' n' t' =case t' ofNil-> n'
Fork l x r -> f' (foldTree' f' n' l) x (foldTree' f' n' r)
buildTree:: (forallbc. (b->a->b->c) ->c->Hyperbc) ->Treea
buildTree g = run (g ForkNil)
zipTree::Treea->Treeb->Tree (a, b)
zipTree xs ys = run $ foldTree xs f Nil. foldTree ys g Nothingwhere
f (Just (l, _, _)) x (Just (_, y, r)) =Fork l (x, y) r
f _ x (Just (l, y, r)) =Fork l (x, y) r
f (Just (l, y, r)) x _ =Fork l (x, y) r
f _ _ _ =Nil
g l y r =Just (l, y, r)
Can hyperfunctions be combined with recursion-schemes?
EDIT: To expand a bit on this. I don't think the example I gave is of much use it is a bit strange and can traverse over the subtrees multiple times. You could fix this by traversing over both trees in the same order (e.g. depth first or breadth first and form left to right or the other way around). I wonder if there are other more complicated zipping patterns for non-list data types that are actually used in practice.
The text was updated successfully, but these errors were encountered:
Like a Tree fold:
Can
hyperfunctions
be combined withrecursion-schemes
?EDIT: To expand a bit on this. I don't think the example I gave is of much use it is a bit strange and can traverse over the subtrees multiple times. You could fix this by traversing over both trees in the same order (e.g. depth first or breadth first and form left to right or the other way around). I wonder if there are other more complicated zipping patterns for non-list data types that are actually used in practice.
The text was updated successfully, but these errors were encountered: