[Haskell-cafe] Dynamic Type Contruction
Vitor Rodrigues
vitor.rodrigues at tugamail.com
Mon Nov 8 06:51:10 EST 2004
I'm trying to create a library to querying XML data using Strafunski. I'm also using DrIFT to generate the instances of Typeable and Term of my Datatypes to be used inside Strafunski.
Supose i've this datatypes:
data Shape = Circle Float (Float,Float) | Triangle (Float, Float) (Float, Float) (Float, Float)
then DrIFT, among other things, creates the functions:
isCircle (Circle _ _ ) = True
isCircle _ = False
isTriangle (Triangle _ _ _) = True
isTriangle _ = False
what i'd like to have "is" as a generic "isFoo" function, with the type:
is :: String -> DataType -> Bool
that when running will act like this:
is "Circle" (Circle 3.4 (3.0,3.1)) = True
is "Triangle" (Circle 3.4 (3.0,3.1)) = False
is "Circle" 2 = False
I was looking on TyCon constructor and mkTyCon function, but i didn't understood it well.
Can anyone tell me how can i create this "is Foo" function?
I was thinking about create a dynamic type with mkTyCon and then see if it matches with the DataType receiveid as function parameter.
Regards,
Vitor Rodrigues
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org//pipermail/haskell-cafe/attachments/20041108/d49ce7ea/attachment.htm
More information about the Haskell-Cafe
mailing list