[Haskell-cafe] Haskell extension/improvement

Ron de Bruijn rondebruijn at yahoo.com
Mon Aug 16 14:45:40 EDT 2004


--- Martin_Sjögren <msjogren at gmail.com> wrote:

> On Mon, 16 Aug 2004 09:01:45 -0700 (PDT), Ron de
> Bruijn
> <rondebruijn at yahoo.com> wrote:
> > I was playing with QuickCheck and I just wanted to
> put
> > all of my tests in a list, but that's not
> possible,
> > because of the fact that a list can only contain
> > values of the same type.
> > 
> > So concrete I would like to write down this:
> > 
> > prop_RevRev xs = reverse (reverse xs) == xs
> >   where types = xs::[Int]
> > 
> > --trivial test
> > prop_Simple = True == True
> > 
> > whatIwant::(Testable a)=>[a]
> > whatIwant = [prop_RevRev, prop_Simple]
> > 
> > testAll::IO ()
> > testAll = do sequence_ $ map quickCheck whatIwant
> 
> > I saw this page:
> > http://www.haskell.org/hawiki/ExistentialTypes
> > 
> > but you still have to explicitly add the relation
> via
> > Obj (and that's bad).
> 
> Well, if you write
> 
> data Test = forall a. Testable a => Test a
> 
> instance Testable Test where
>   property (Test x) = property x
> 
> you at least get the "unwrapping" for free, and can
> write things like
> 
> mapM_ quickCheck [Test prop_revrev, Test
> prop_trivial, Test prop_something]
> 
> 
> Regards,
> Martin
> 
I didn't expect these replies (including one
mentioning the HList idea(the enforced ordening is
nice, though)), while I tried to be precise. The idea
is that you don't write down the Test constructor in
any place, because you(that's the compiler) can check
that all the values you put in the list(or any other
datastructure) belong to a certain class. Everything
that can be derived should be derived. 

Regards, Ron



		
__________________________________
Do you Yahoo!?
Take Yahoo! Mail with you! Get it on your mobile phone.
http://mobile.yahoo.com/maildemo 


More information about the Haskell-Cafe mailing list