Skip to content

Instantly share code, notes, and snippets.

@kowey
Created January 23, 2010 16:01
Show Gist options
  • Save kowey/284659 to your computer and use it in GitHub Desktop.
Save kowey/284659 to your computer and use it in GitHub Desktop.
-- Rabhi and Lapalme, Algorithms: A Functional Programming Approach, pg 80
data BinTree a = Empty | NodeBT a (BinTree a) (BinTree a) deriving Show
ex = NodeBT 42 (NodeBT 4 Empty Empty) (NodeBT 2 Empty Empty)
comp'' x Empty = (Empty, 0)
comp'' x (NodeBT v lf rt) = ( NodeBT (fromIntegral v / fromIntegral x) p1 p2
, v + s1 + s2 )
where
(p1,s1) = comp'' x lf
(p2,s2) = comp'' x rt
comp' t = t'
where (t',x) = comp'' x t
-- I have a hard time with the 'x' here (in t',x)
-- is that tying the knot?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment