[Haskell-cafe] ANNOUNCE: Agata-0.2.0

Jonas Almström Duregård jonas.duregard at gmail.com
Tue Apr 20 16:38:59 EDT 2010

Hi Neil and Sebastiaan,

Thanks for the constructive criticism ;).

As far as i can tell, derive only works for regular and linear
recursive types and Regular uses frequencies to regulate size. (Also
Regular doesn't seem to work for QuickCheck-2).

I think I may have used a too simple example in my original post. Here
is a more complicated one:

>data TrinaryTree a =
>    Branch a (TrinaryTree a) (TrinaryTree a) (TrinaryTree a)
>  | Empty deriving Show
>$(agatath $ derive ''TrinaryTree)

With the derive tool, generated values would typically be infinite.

With Regular, the user would need to specify frequencies, and even
then the generator would be useless because of the low frequency
required for "Branch" to ensure termination (most generated trees
would be empty, and almost none would contain several branches).

Most of the work i have done on Agata is to make a class that
resembles arbitrary (i.e. can be used to construct generators) but
where the instances can be defined mechanically from the definition of
instantiated types. The reason i didn't use Generics for defining the
instances is that I was unsure if/how it distinguishes mutually
recursive fields.

Another feature of Agata generators is improved scalability compared
to other QuickCheck generators, especially for nested collection data
types (analog to [[[[a]]]] and such). The details of how this works in
Agata will one day be explained in the documentation, but the
principle is explained in my masters thesis[1].


[1] http://gupea.ub.gu.se/bitstream/2077/22087/1/gupea_2077_22087_1.pdf

2010/4/20 Sebastiaan Visser <sfvisser at cs.uu.nl>:
> Jonas,
> You can also derive (Co)Arbitrary instances automatically using the regular-extras package based on the Regular generic programming library.
> The advantage of using a library like Regular is that you do not have to write any Template Haskell code. The library generates a nice algebraic generic view on your datatype that you can use to write your generic functions. The Regular library itself of course uses TH internally, but this is done once and all datatype generic functions can piggy bag on the same TH derivation. For example, look at Generics.Regular.Functions.Arbitrary, this module is really concise.
> Nice work though!
> Gr,
> Sebastiaan
> On Apr 18, 2010, at 1:43 AM, Jonas Almström Duregård wrote:
>> I'm pleased to announce Agata (Agata Generates Algebraic Types Automatically)!
>> Avoiding excessive details, usage is best described by a small example:
>> {-#LANGUAGE TemplateHaskell #-}
>> import Test.QuickCheck
>> import Test.AgataTH
>> data X a b = X [Either a b] deriving Show
>> data Y = Y deriving Show
>> data Z = Z deriving Show
>> $(agatath $ deriveall [''X,''Y,''Z])
>> main = sample (arbitrary :: Gen (X Y Z))
>> This code derives instances of Test.QuickCheck.Arbitrary for the data
>> types X, Y and Z.
>> http://hackage.haskell.org/package/Agata
>> Regards Jonas

More information about the Haskell-Cafe mailing list