[Haskell-cafe] Haskell extension/improvement
Martin Sjögren
msjogren at gmail.com
Mon Aug 16 13:09:24 EDT 2004
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
More information about the Haskell-Cafe
mailing list