Skip to content

Instantly share code, notes, and snippets.

@ChrisPenner
Last active January 7, 2017 22:42
Show Gist options
  • Save ChrisPenner/aa6083478d2d1100f62a974860aae529 to your computer and use it in GitHub Desktop.
Save ChrisPenner/aa6083478d2d1100f62a974860aae529 to your computer and use it in GitHub Desktop.
Recursion schemes test
error:
• Couldn't match type ‘Base (Fix WindowF Bool)’ with ‘WindowF Bool’
Expected type: Base (Fix WindowF Bool) Bool -> Bool
Actual type: WindowF Bool Bool -> Bool
• In the first argument of ‘cata’, namely ‘alg’
In the expression: cata alg w
In an equation for ‘allActive’:
allActive (Window w)
= cata alg w
where
alg (Split _ _ l r) = l && r
alg (Single _ b) = b
data Dir = Hor
| Vert
deriving (Show)
data WindowF r a =
Split Dir SplitInfo r r
| Single ViewInfo a
deriving (Show, Functor)
instance Bifunctor WindowF where
bimap f _g (Split dir si x y) = Split dir si (f x) (f y)
bimap _f g (Single vi a) = Single vi (g a)
newtype Window a = Window (Fix WindowF a) deriving Functor
allTree :: Window Bool -> Bool
allTree (Window w) = cata alg w
where
alg (Split _ _ x y) = x && y
alg (Single _ x) = x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment