[Haskell-cafe] Generating arbitrary functions with QuickCheck?

Matias Eyzaguirre dented42 at gmail.com
Wed Sep 15 11:29:01 EDT 2010

I'v been reading a small paper/lesson on writing parser combinators in Haskell, and it seems more or less straightforward. In this case a parser is defined thusly:
> type Parser a = String -> Maybe (a, String)
And then it goes on to list some simple parsers, and then starts going on about combinators.
I was wondering how one would write quickcheck properties for the items presented in the paper, and the answer seemed fairly straightforward for the actual parsers. But how on earth would you write a test for a combinator? Presumable one would need to make the type an instance of Arbitrary.
I see two problems:
Firstly, as far as i can tell, one cannot declare a type synonym to be an instance of a type class, thus how would you make it an instance of Arbitrary?
Secondly, (and more importantly, or at least more interesting) I can see how one would make a generator for simple compound data types, but how on earth do you make a generator produce functions?

More information about the Haskell-Cafe mailing list