Skip to content

Instantly share code, notes, and snippets.

@byorgey
Created October 13, 2012 16:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save byorgey/3885121 to your computer and use it in GitHub Desktop.
Save byorgey/3885121 to your computer and use it in GitHub Desktop.
Creating a tree with shared links back to parent nodes
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" []]
@byorgey
Copy link
Author

byorgey commented Oct 13, 2012

Here's a visualization of tie exAcct after being fully evaluated, using ghc-vis:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment