[Haskell-cafe] Automatic derivation (TemplateHaskell?)

Joel Reymont joelr1 at gmail.com
Wed Apr 4 19:14:52 EDT 2007


Folks,

I have very uniform Parsec code like this and I'm wondering if I can  
derive it using TemplateHaskell or DrIFT or some other tool. Any ideas?

Note that

1) The reserved word matches the constructor

2) No arguments equals no parens

3) More than one argument is separated with a comma

4) For every invocation of numExpr, strExpr or boolExpr, the type of  
the constructor argument is NumExpr, StrExpr and BoolExpr respectively.

This is just a handful of functions and I have to tackle about 100  
more, thus my asking :-).

	Thanks, Joel

---

strCall =
     choice [ do { reserved "NewLine"
                 ; return NewLine
                 }
            , do { reserved "GetSymbolName"
                 ; return GetSymbolName
                 }
            , do { reserved "ELDateToString"
                 ; arg1 <- parens numExpr
                 ; return $ ELDateToString arg1
                 }
            , do { reserved "TextGetString"
                 ; arg1 <- parens numExpr
                 ; return $ TextGetString arg1
                 }
            , do { reserved "Description"
                 ; return Description
                 }
            , do { reserved "GetExchangeName"
                 ; return GetExchangeName
                 }
            , do { reserved "LeftStr"
                 ; parens $ do { arg1 <- strExpr
                               ; comma
                               ; arg2 <- numExpr
                               ; return $ LeftStr arg1 arg2
                               }
                 }
            , do { reserved "RightStr"
                 ; parens $ do { arg1 <- strExpr
                               ; comma
                               ; arg2 <- numExpr
                               ; return $ RightStr arg1 arg2
                               }
                 }
            , do { reserved "LowerStr"
                 ; arg1 <- parens strExpr
                 ; return $ LowerStr arg1
                 }
            , do { reserved "UpperStr"
                 ; arg1 <- parens strExpr
                 ; return $ UpperStr arg1
                 }
            , do { reserved "Spaces"
                 ; arg1 <- parens numExpr
                 ; return $ Spaces arg1
                 }
            , do { reserved "SymbolRoot"
                 ; return SymbolRoot
                 }
            , do { reserved "MidStr"
                 ; parens $ do { arg1 <- strExpr
                               ; comma
                               ; arg2 <- numExpr
                               ; comma
                               ; arg3 <- numExpr
                               ; return $ MidStr arg1 arg2 arg3
                               }
                 }
            , do { reserved "NumToStr"
                 ; parens $ do { arg1 <- numExpr
                               ; comma
                               ; arg2 <- numExpr
                               ; return $ NumToStr arg1 arg2
                               }
                 }
            ]

--
http://wagerlabs.com/







More information about the Haskell-Cafe mailing list