
Hi all, Is it possible to define a limit for the size of children list bellow? I've tried: children <- resize (10 (listGen featureGenNormal)) But it didn't work. Thanks a lot, Rodrigo.
Sebastian Sylvan:
featureGenNormal = do id <- stringGen name <- stringGen featuretype <- arbitrary grouptype <- arbitrary children <- arbitrary properties <- listGen stringGen return (Feature id name featuretype grouptype children properties)
Ryan Ingram wrote:
Also, you can shorten this significantly with liftM or ap (from Control.Monad):
True, but in this case I like being able to see meaningful names for each parameter of the constructor.
----------------------------------- Rodrigo Bonifácio de Almeida Universidade Católica de Brasília - Grupo de Engenharia de Software - JavaComBr (www.ucb.br/java)

On 17 mar 2008, at 14.37, rodrigo.bonifacio wrote:
Hi all,
Is it possible to define a limit for the size of children list bellow?
I've tried:
children <- resize (10 (listGen featureGenNormal))
You are calling a number as a function. Also, listGen has to use the size argument. Try something like (not tested): listGen = sized (\maxSize -> do n <- arbitrary x <- g xs <- frequency [ (1, return []), (n, listGen g) ] return (x:xs)

On Mon, Mar 17, 2008 at 1:54 PM, Thomas Schilling
On 17 mar 2008, at 14.37, rodrigo.bonifacio wrote:
Hi all,
Is it possible to define a limit for the size of children list bellow?
I've tried:
children <- resize (10 (listGen featureGenNormal))
You are calling a number as a function.
Also, listGen has to use the size argument. Try something like (not tested):
listGen = sized (\maxSize -> do n <- arbitrary x <- g xs <- frequency [ (1, return []), (n, listGen g) ] return (x:xs)
In retrospect, this function isn't very good at all, because it never generates the empty list... Something like this is probably better (untested): listGen g = sized (\maxSize -> do count <- choose (0, maxSize - 1) replicateM count g ) -- Sebastian Sylvan +44(0)7857-300802 UIN: 44640862
participants (4)
-
Henning Thielemann
-
rodrigo.bonifacio
-
Sebastian Sylvan
-
Thomas Schilling