Created
September 25, 2012 06:58
-
-
Save horus/3780368 to your computer and use it in GitHub Desktop.
replaceMin problem & value recursion
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
{-# LANGUAGE DoRec #-} | |
data Tree a = L a | B (Tree a) (Tree a) | |
deriving (Show) | |
rpMinWithIO :: (Ord a, Show a) => (Tree a, a) -> IO (Tree a, a) | |
rpMinWithIO (L a, m) = print a >> return (L m, a) | |
rpMinWithIO (B l r, m) = | |
rpMinWithIO (l, m) >>= | |
\(l', lmin) -> | |
rpMinWithIO (r, m) >>= | |
\(r', rmin) -> | |
return (B l' r', min lmin rmin) | |
replaceMinWithIO :: (Ord a, Show a) => Tree a -> IO (Tree a) | |
replaceMinWithIO tree = do { rec (tree', m) <- rpMinWithIO (tree, m) | |
; return tree' | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment