Last active
August 29, 2015 14:01
-
-
Save mrb/3bdc9e9ba183c364482a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Main | |
import Effect.State | |
data BTree a = Leaf | |
| Node (BTree a) a (BTree a) | |
instance Show a => Show (BTree a) where | |
show Leaf = "[]" | |
show (Node l x r) = "[" ++ show l ++ " " | |
++ show x ++ " " | |
++ show r ++ "]" | |
testTree : BTree String | |
testTree = Node (Node Leaf "Jim" Leaf) | |
"Fred" | |
(Node (Node Leaf "Alice" Leaf) | |
"Sheila" | |
(Node Leaf "Bob" Leaf)) | |
treeTagAux : BTree a -> { [STATE (List a)] } Eff m (BTree ((List a), a)) | |
treeTagAux Leaf = pure Leaf | |
treeTagAux (Node l x r) | |
= do l' <- treeTagAux l | |
i <- get | |
put (x::i) | |
r' <- treeTagAux r | |
pure (Node l' (i, x) r') | |
treeTag : (i : (List a)) -> BTree a -> BTree ((List a), a) | |
treeTag i x = runPure (do put i | |
treeTagAux x) | |
main : IO () | |
main = print (treeTag [] testTree) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment