diff --git a/src/Stream.hs b/src/Stream.hs index 608f124..fbb8d9d 100644 --- a/src/Stream.hs +++ b/src/Stream.hs @@ -16,6 +16,7 @@ instance Functor Stream where Stream $ (\(a, stream) -> (f a, fmap f stream)) <$> pairs instance Tree Stream where + getStructure (Stream []) = Leaf getStructure (Stream pairs) = Node $ (\(s, stream) -> (s, getStructure stream)) <$> pairs diff --git a/src/Tree.hs b/src/Tree.hs index 43c3d05..2ca262d 100644 --- a/src/Tree.hs +++ b/src/Tree.hs @@ -3,7 +3,7 @@ module Tree ( , Structure(..) ) where -data Structure = Node [(String, Structure)] +data Structure = Leaf | Node [(String, Structure)] class Functor a => Tree a where getStructure :: a String -> Structure @@ -12,7 +12,8 @@ class Functor a => Tree a where draw = unlines . getLines . getStructure . fmap show getLines :: Structure -> [String] -getLines (Node []) = ["╼"] +getLines Leaf = ["╼"] +getLines (Node []) = [""] getLines (Node [(s, structure)]) = showBlock '─' (s, structure) getLines (Node ((s, structure):pairs)) = concat $ showBlock '┬' (s, structure) : showBlocks pairs