[Haskell-cafe] Language.Haskell.Parser question
Vasyl Pasternak
vasyl.pasternak at gmail.com
Thu Mar 26 18:38:40 EDT 2009
Wow, uniplate is the library from my dreams :)
I knew there should be easy, elegant and simple solution (I hate brute
force, that's why I start using Haskell).
Many thanks.
2009/3/26 Neil Mitchell <ndmitchell at gmail.com>:
> Hi
>
>> 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
> Language.Haskell did.
>
>> 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:
> http://community.haskell.org/~ndm/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.
>
> Thanks
>
> Neil
>
--
Best regards,
Vasyl Pasternak
More information about the Haskell-Cafe
mailing list