Created
May 23, 2017 14:39
-
-
Save bananu7/88190fcbe5af0954e31be2a4dc1c520d to your computer and use it in GitHub Desktop.
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
| data Tree = | |
| NodeLeaf Int | | |
| NodeA Tree | | |
| NodeB Tree | |
| processTree :: Tree -> IO () | |
| processTree (NodeLeaf a) = putStr . show $ a | |
| processTree (NodeA t) = putStr "a-" >> processTree t | |
| processTree (NodeB t) = putStr "b-" >> processTree t | |
| -- Simply add P | |
| type P = Int | |
| data TreeP = | |
| NodeLeafP Int P | | |
| NodeAP TreeP P | | |
| NodeBP TreeP P | |
| processTreeP :: TreeP -> IO () | |
| processTreeP (NodeLeafP a p) = putStrLn $ show a ++ ":" ++ show p | |
| processTreeP (NodeAP t p) = (putStr $ "a:" ++ show p ++ "-") >> processTreeP t | |
| processTreeP (NodeBP t p) = (putStr $ "b:" ++ show p ++ "-") >> processTreeP t | |
| -- create wrapped nodes | |
| data WithP a = WithP a P | |
| data TreeW = | |
| NodeLeafW (WithP Int) | | |
| NodeAW (WithP TreeW) | | |
| NodeBW (WithP TreeW) | |
| main = do | |
| processTree (NodeA (NodeB (NodeLeaf 5))) | |
| putStrLn "" | |
| processTreeP (NodeAP (NodeBP (NodeLeafP 5 3) 2) 1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment