Created
October 13, 2012 16:01
-
-
Save byorgey/3885121 to your computer and use it in GitHub Desktop.
Creating a tree with shared links back to parent nodes
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
type AccountName = String | |
data Account = Account { | |
aname :: AccountName, | |
asubs :: [Account] | |
} | |
deriving Show | |
data Account2 = Account2 { | |
aname2 :: AccountName, | |
aparent2 :: Maybe Account2, | |
asubs2 :: [Account2] | |
} | |
tie :: Account -> Account2 | |
tie = tie' Nothing | |
where | |
tie' parent (Account nm subs) | |
= let acct = Account2 nm parent (map (tie' (Just acct)) subs) | |
in acct | |
exAcct = | |
Account "foo" [Account "bar" [Account "baz" []], Account "quux" []] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here's a visualization of
tie exAcct
after being fully evaluated, using ghc-vis: