[Haskell-cafe] Language.Haskell.Parser question
ndmitchell at gmail.com
Thu Mar 26 13:17:03 EDT 2009
> f1 = foo 5
> f2 = foo 8
> f3 = foo 9
> I want to extract a list [5, 8, 9] (suppouse function takes only one argument)
Firstly, use haskell-src-exts and Language.Haskell.Exts - its a much
better library, deals with many extensions, and gives you everything
> parser works pretty good,
> but its output data type is terrible. As I understand, I need to
> extract all objects that looks like
> HsApp (HsVar (UnQual (HsIdent "foo"))) ....
It's trivial, if you use a generics solution, say Uniplate:
[x | App foo x <- universeBi src, prettyPrint foo == "foo" ]
I often use prettyPrint to follow down Ident/Qual/UnQual paths without
having to know as much of the data type. Using universeBi makes it
easy to find everything that occurs everywhere.
If you attempt this without using a generics library, I'd say you are
destined to fail.
More information about the Haskell-Cafe