[Haskell-cafe] Dynamic Type Contruction

Ralf Laemmel Ralf.Laemmel at cwi.nl
Mon Nov 8 09:07:59 EST 2004


Vitor,

That's amazing!!! Your question is very timely! :-)

You know ... someone just challenged me with this question,
and I added the corresponding function to the boilerplate testsuite.
However, it is much more typeful than you propose.
I call it the "typeful reflection benchmark".

http://www.cs.vu.nl/boilerplate/#suite
http://www.cs.vu.nl/boilerplate/testsuite/getC.hs

So you actually can write isC Circle <some term>.
No string encoding!
No possible confusion of different term types.

Ralf

Oops: I leave it as an exercise to implement this boilerplate pearl in 
Strafunski :-)

Vitor Rodrigues wrote:

> 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
>  
>
>------------------------------------------------------------------------
>
>_______________________________________________
>Haskell-Cafe mailing list
>Haskell-Cafe at haskell.org
>http://www.haskell.org/mailman/listinfo/haskell-cafe
>  
>




More information about the Haskell-Cafe mailing list