Haskell extension/improvement

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 quickCheck can work on all Testable values, so why can't a list (any datastructure) can't hold Testable values? What this gives you is, a lot more flexibility. Just like you can define your functions on interfaces, now you can use interfaces in your datastructures. I can't think of any reason why it couldn't be implemented in any Haskell compiler. 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). Regards, Ron P.S. If it already exist in this exact way, how is it called? _______________________________ Do you Yahoo!? Express yourself with Y! Messenger! Free. Download now. http://messenger.yahoo.com

On Mon, 16 Aug 2004 09:01:45 -0700 (PDT), Ron de Bruijn
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

--- Martin_Sj�gren
I was playing with QuickCheck and I just wanted to
all of my tests in a list, but that's not
On Mon, 16 Aug 2004 09:01:45 -0700 (PDT), Ron de Bruijn
wrote: put 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

Ron de Bruijn wrote:
--- Martin_Sjögren
wrote:
[...]
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.
(The following is adapted from a message in a previous thread, but I forget whose it was.) If you only wanted to minimise the number of tokens, you could rewrite test = quickCheck a >> quickCheck b >> quickCheck c as m & p = m >> quickCheck p -- reusable test = quickCheck a & b & c which is about as succinct as the list notation. Regards, Tom
participants (3)
-
Martin Sjögren
-
Ron de Bruijn
-
Tom Pledger