Implementando `read` para uma árvore associativa à esquerda em Haskell
Estou com dificuldades para implementarLer para uma estrutura de árvore. Eu quero pegar uma corda associativa à esquerda (com parênteses) comoABC(DE)F
e convertê-lo em uma árvore. Esse exemplo específico corresponde à árvore
Aqui está o tipo de dados que estou usando (embora esteja aberto a sugestões):
data Tree = Branch Tree Tree | Leaf Char deriving (Eq)
Essa árvore em particular seria, em Haskell:
example = Branch (Branch (Branch (Branch (Leaf 'A')
(Leaf 'B'))
(Leaf 'C'))
(Branch (Leaf 'D')
(Leaf 'E')))
(Leaf 'F')
Minhasshow
função parece com:
instance Show Tree where
show (Branch l r@(Branch _ _)) = show l ++ "(" ++ show r ++ ")"
show (Branch l r) = show l ++ show r
show (Leaf x) = [x]
Eu quero fazer umread
função de modo que
read "ABC(DE)F" == example