9 Feb 2013 08:07
CoArbitrary
Tony Morris <tonymorris <at> gmail.com>
2013-02-09 07:07:54 GMT
2013-02-09 07:07:54 GMT
Hello, In the QuickCheck library, there is a type-class called CoArbitrary. It is defined like so: class CoArbitrary a where coarbitrary :: a -> Gen b -> Gen b -- Gen is a monad Its purpose is to allow generation of functions. In other words, for taking Gen x -> Gen (a -> x), which could be done rather degenerately (fmap const) but QuickCheck constrains with (CoArbitrary a) to perturb the resulting value instead of ignoring (const) it. It has always puzzled me in the general sense of thinking about the scenario: f x -> f (a -> x) and whether the CoArbitrary is a good/general solution, perhaps for the specific case of f=Gen or maybe even more generally. -- approximate (a -> f x -> f x) -- e.g. CoArbitrary to perturb the result -> f x -- e.g. Gen x -> f (a -> x) -- e.g. Gen (a -> x) So I often wonder about what might be a better (and perhaps more general) constraint to produce functions f x -> f (a -> x) for a given Monad f. I was wondering if there is an existing abstraction (or paper) that might point me in that direction. It is a problem that I encounter on occasion in general programming and I am using Arbitrary/CoArbitrary as an example to help make my point, but I am dissatisfied (for reasons that I am unsure about) with the solution provided by CoArbitrary.(Continue reading)
RSS Feed