1100ÆÚÄ©¸´Ï°
/List
nameOfList :: [a] -> b nameOfList list = case list of
[] -> _
x:xs -> f x nameOfList xs
nameOfList2 :: [a] -> b nameOfList2 list = case list of
[] -> _
[x]-> _
x:y:xs -> f x y nameOfList2 xs
Binary Tree
nameOfBT :: BinaryTree a -> b nameOfBT tree = case tree of
Null -> _
Node n1 a n2 -> Node (nameOfTree n1) (f a) (nameOfTree n2)
nameOfRT :: RoseTree a -> b nameOfRT (RT a list) = case list of
[] -> RT (f a) []
_ -> RT (f a) (map nameOfRT list)
nameOfRT2 :: RoseTree a -> b nameOfRT2 (RT a list) = case list of
[] -> RT (f a) []
_ -> RT (f a) (helper list)
Helper :: [RoseTree a] -> [RoseTree a] Helper list = case list of
[] -> []
RT a list:xs -> (nameOfRT2 (RT a list)): Helper xs
RoseTree