Skip to content

Instantly share code, notes, and snippets.

@amiller
Created August 22, 2012 08:54
Show Gist options
  • Save amiller/3423868 to your computer and use it in GitHub Desktop.
Save amiller/3423868 to your computer and use it in GitHub Desktop.
import Control.Monad
-- HashGraph
class HashGraph digest value m where
hash :: value -> m digest
unhash :: digest -> m value
instance (Monad m) => HashGraph a a m where
hash = return
unhash = return
-- RedBlack Tree Balancing
data Color = R | B deriving Show
data Tree k d = E | T Color d k d deriving Show
insert :: (Ord k, Monad m,
HashGraph d (Tree k (m d)) m) =>
k -> (Tree k (m d)) -> m d
insert k E = hash $ T B (return E) k (return E)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment