, Tree, . ! ? , . !
-, , , Int, t. :
data TNode t a = Empty
| Leaf a
| Node (t a) a (t a)
deriving (Eq, Ord, Show, Read)
TNode , ; . , , TNode :
newtype Tree a = Tree (TNode Tree a) deriving (Eq, Ord, Show, Read)
Tree , , , , :
Tree (Node (Tree Empty) 5 (Tree (Leaf 2)))
, , , ? , , .
, , - . , :
newtype NameTree a = NameTree (String, TNode NameTree a) deriving (Eq, Ord, Show, Read)
, :
toList f t = toList' f (f t) []
where toList' f (Node t1 x t2) xs = toList' f (f t1) (x : toList' f (f t2) xs)
toList' f (Leaf x) xs = x:xs
toList' _ Empty xs = xs
TNode , :
treeToList = toList (\(Tree t) -> t)
nameTreeToList = toList (\(NameTree (_, t)) -> t)
, , , , , , Haskell (, ) .