Tony Morris | 9 Feb 08:07 2013
Picon

CoArbitrary

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)

Stephen Tetley | 9 Feb 11:50 2013
Picon

Re: CoArbitrary

I think GAST - the Clean equivalent of Quickcheck - generates
functions. There are certainly quite a few papers by members of the
Clean team documenting how they generate them.

On 9 February 2013 07:07, Tony Morris <tonymorris <at> gmail.com> wrote:
[...]
> I hope I have phrased this in a way to make the point. I found it a bit
> difficult to articulate and I do wonder (hope!) that others encounter
> similar scenarios. Thanks for any tips!
Roman Cheplyaka | 9 Feb 22:08 2013

Re: CoArbitrary

I don't think the question was about generating functions...
FWIW, both QuickCheck and SmallCheck generate functions. There was also
an interesting paper at the last ICFP by Koen related to this.

But I think Tony is looking for some kind of a pattern here...

Roman

* Stephen Tetley <stephen.tetley <at> gmail.com> [2013-02-09 10:50:45+0000]
> I think GAST - the Clean equivalent of Quickcheck - generates
> functions. There are certainly quite a few papers by members of the
> Clean team documenting how they generate them.
> 
> On 9 February 2013 07:07, Tony Morris <tonymorris <at> gmail.com> wrote:
> [...]
> > I hope I have phrased this in a way to make the point. I found it a bit
> > difficult to articulate and I do wonder (hope!) that others encounter
> > similar scenarios. Thanks for any tips!
> 
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe <at> haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
Tony Morris | 10 Feb 09:33 2013
Picon

Re: CoArbitrary

On 09/02/13 15:08, Roman Cheplyaka wrote:
> I don't think the question was about generating functions...
> FWIW, both QuickCheck and SmallCheck generate functions. There was also
> an interesting paper at the last ICFP by Koen related to this.
>
> But I think Tony is looking for some kind of a pattern here...
>
> Roman
>
> * Stephen Tetley <stephen.tetley <at> gmail.com> [2013-02-09 10:50:45+0000]
>> I think GAST - the Clean equivalent of Quickcheck - generates
>> functions. There are certainly quite a few papers by members of the
>> Clean team documenting how they generate them.
>>
>> On 9 February 2013 07:07, Tony Morris <tonymorris <at> gmail.com> wrote:
>> [...]
>>> I hope I have phrased this in a way to make the point. I found it a bit
>>> difficult to articulate and I do wonder (hope!) that others encounter
>>> similar scenarios. Thanks for any tips!
>> _______________________________________________
>> Haskell-Cafe mailing list
>> Haskell-Cafe <at> haskell.org
>> http://www.haskell.org/mailman/listinfo/haskell-cafe
Yeah I am looking for a possible pattern. I am struggling to explain the
problem. Perhaps some code will help.

This code compiles, however the function "problem" is the one I am
looking for. There are two data structures here:
1) Op, which is a functor
2) FreeOp, which is a monad that arises from the Op functor (i.e. an
(Continue reading)


Gmane