nntpnews.net

Global Usenet Archiver


Register

[Haskell-cafe] Generating repeatable arbitrary values withQuickCheck 2

Reply

  #11  
Old 05-02-10, 10:14 PM
David Menendez
 
Posts: n/a
Default Re: [Haskell-cafe] Re: Generating repeatable arbitrary values withQuickCheck 2

On Fri, Feb 5, 2010 at 3:39 PM, Ryan Ingram < - > wrote:
> On Fri, Feb 5, 2010 at 5:19 AM, Martijn van Steenbergen
> < - > wrote:
>> Ryan Ingram wrote:
>>>
>>> Unfortunately, this makes things like
>>>>
>>>> *infinite_xs <- sequence (repeat arbitrary)
>>>
>>> no longer work, since the state never comes out the other side.

>>
>> You're asking to execute an infinite number of monadic actions. How can this
>> ever terminate at all?

>
> Stefan already gave an example, but to explain slightly further --
>
> There's nothing "magical" about monadic actions. *It's just another
> function call.
>
> In the case of QuickCheck, Gen is a reader monad with a "broken" >>=
> that changes the state of the generator passed to each side:


Incidentally, the alternative Gen I suggested also works for infinite
lists. (It's equivalent to StateT StdGen (Reader Int), using the
StateT from Control.Monad.State.Lazy.)

The problem, as Ryan pointed out, is that you can't access the state
after the infinite computation, so you can't create two infinite
streams or an infinite tree, which the current definition of Gen
allows.

More concretely, this works fine:

stream = do
x <- arbitrary
xs <- stream
return (x:xs)

but you can't call arbitrary after you call stream

broken = do
xs <- stream
y <- arbitrary -- can't evaluate until stream is fully evaluated
(i.e., never)

The present definition of Gen avoids this by splitting the StdGen at
every >>=, but that creates the situation where two expressions which
should be equivalent produce different results in some contexts.

It isn't clear to me which implementation is best. I lean towards the
StateT-like implementation, on the theory that it's limitations are
easier to explain, but I guess it comes down to whether we want to
make life easier for (a) people creating infinite structures or (b)
people who need reproducible results.

--
Dave Menendez < - >
<http://www.eyrie.org/~zednenem/>
_______________________________________________
Haskell-Cafe mailing list
Code:
Content visible to registered users only.
Code:
Content visible to registered users only.
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
[Haskell-cafe] Generating Haskell From a XSD jonathanGfischoff@gmail.com fa.haskell 2 23-12-09 06:11 PM
[Haskell-cafe] Testing nested implication properties withQuickCheck? Ahn, Ki Yung fa.haskell 1 27-07-09 10:18 PM
[Haskell-cafe] Generating Haskell with associated types (and kindannotations) Daniel Peebles fa.haskell 4 09-05-09 02:54 PM
[Haskell-cafe] Generating arbitrary function in QuickCheck Yusaku Hashimoto fa.haskell 5 08-04-09 04:31 AM
[Haskell-cafe] How to choose an arbitrary Arbitrary? Bas van Dijk fa.haskell 2 18-12-08 09:24 AM


All times are GMT +1. The time now is 10:52 PM. Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0



For ads on this site use independent advertising companies. These companies may use some data (which does not include your name, address, email address or telephone number) about your visits to this and other websites to create advertisements on products and services you might enjoy. If you'd like more information and to know the options available to prevent the use of such information by these companies, click here

Abuse Ticket System