haskell - How to parse a tree-like structure using PArrows? -


i'm trying learn arrows, how parrows can replace parsec, there nonexistent number of tutorials. believe benefit lot simple examples, so, given binary tree:

data tree = node tree tree | | b deriving show 

how can parrow used parse string similar to:

"((a b) (a (b a)))"  

so becomes:

node (node b) (node (node b a)) 

this not cleanest answer, managed with:

import text.parsercombinators.parrow import control.arrow  data tree = node tree tree | | b deriving show  text = "((b a) (a b))"  fromtoken :: char -> tree fromtoken 'a' = fromtoken 'b' = b  token = anyof "ab" >>> arr fromtoken node = arr (uncurry node)      <<< ((char '(' >>> token <+> node)   -- left side     >>! white                            -- whitespace     &&& ((token <+> node) >>! char ')')) -- right side  main = print $ runparser node text 

mind i'm still working on arrow familiarity.


Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -