
Hi all, There is something about polymorphic tests in QuickCheck that I do not understand. If you write the simplest dummy test function tst :: a -> Bool tst _ = True and evaluate it we get
verboseCheck tst 0: () 1: () ...
How come did the polymorphic value a get instanciated to ()? Is this done via the Testable type class? Could someone please explain this to me? I'm not saying it does not make sense, but I would like to understand how it works. Being possible to change this behavior, this is, assign another "default type" whenever polymorphic types occur, would be awesome. Cheers, hugo -- www.di.uminho.pt/~hpacheco

2008/6/17 Hugo Pacheco
Hi all, There is something about polymorphic tests in QuickCheck that I do not understand. If you write the simplest dummy test function tst :: a -> Bool tst _ = True and evaluate it we get
verboseCheck tst 0: () 1: () ... How come did the polymorphic value a get instanciated to ()? Is this done via the Testable type class?
I haven't got something here to check with, but from the formatting it looks like every odd line is a randomly-chosen boolean value, and the following line is the result? It might be just printing the result value of IO (). Maybe try a more complete test to see how that looks? Cheers, D -- Dougal Stanton dougal@dougalstanton.net // http://www.dougalstanton.net

It does not seem like printing the result value from IO (), because with a
more complicated example for lists.
t :: [a] -> Bool
t x = True
then it randomly generates values of type [()].
*Quick> verboseCheck t
0:
[]
1:
[()]
2:
[(),(),()]
3:
[]
4:
[()]
5:
[(),(),(),()]
I just wonder how the a got instantiated to ().
Thanks,
hugo
On Tue, Jun 17, 2008 at 11:05 AM, Dougal Stanton
2008/6/17 Hugo Pacheco
: Hi all, There is something about polymorphic tests in QuickCheck that I do not understand. If you write the simplest dummy test function tst :: a -> Bool tst _ = True and evaluate it we get
verboseCheck tst 0: () 1: () ... How come did the polymorphic value a get instanciated to ()? Is this done via the Testable type class?
I haven't got something here to check with, but from the formatting it looks like every odd line is a randomly-chosen boolean value, and the following line is the result? It might be just printing the result value of IO (). Maybe try a more complete test to see how that looks?
Cheers,
D
-- Dougal Stanton dougal@dougalstanton.net // http://www.dougalstanton.net
-- www.di.uminho.pt/~hpacheco

On Jun 17, 2008, at 11:53 AM, Hugo Pacheco wrote:
Hi all,
There is something about polymorphic tests in QuickCheck that I do not understand.
If you write the simplest dummy test function
tst :: a -> Bool tst _ = True
and evaluate it we get
verboseCheck tst 0: () 1: () ...
How come did the polymorphic value a get instanciated to ()? Is this done via the Testable type class? Could someone please explain this to me? I'm not saying it does not make sense, but I would like to understand how it works. Being possible to change this behavior, this is, assign another "default type" whenever polymorphic types occur, would be awesome.
I think it is GHCi that is instantiating the type with (). Try compiling the program, it will probably be rejected by the compiler when you do not specify a concrete type. You can, for example, try this: verboseCheck (tst :: [Int] -> Bool)
Cheers, hugo

You are right!
If I try to compile it, then it complains about a Show instance for a, what
in fact forces a monomorphic type signature for t.
I have found under Test.Quickcheck.Poly a way to generate Int values for a
polymorphic type, but because it requires an abstraction Poly a for some
type a I do not see how it can improve.
What it concretely states the module is
- This is the basic pseudo-polymorphic object.
- The idea is you can't cheat, and use the integer
- directly, but need to use the abstraction.
Is it possible to cheat? I would like to...
Thanks,
hugo
On Tue, Jun 17, 2008 at 12:17 PM, Sebastiaan Visser
On Jun 17, 2008, at 11:53 AM, Hugo Pacheco wrote:
Hi all,
There is something about polymorphic tests in QuickCheck that I do not understand.
If you write the simplest dummy test function
tst :: a -> Bool tst _ = True
and evaluate it we get
verboseCheck tst 0: () 1: () ...
How come did the polymorphic value a get instanciated to ()? Is this done
via the Testable type class? Could someone please explain this to me? I'm not saying it does not make sense, but I would like to understand how it works. Being possible to change this behavior, this is, assign another "default type" whenever polymorphic types occur, would be awesome.
I think it is GHCi that is instantiating the type with (). Try compiling the program, it will probably be rejected by the compiler when you do not specify a concrete type.
You can, for example, try this:
verboseCheck (tst :: [Int] -> Bool)
Cheers,
hugo
-- www.di.uminho.pt/~hpacheco
participants (3)
-
Dougal Stanton
-
Hugo Pacheco
-
Sebastiaan Visser