Hi,
Better late than never :)
Den 2013-02-03 08:30:29 skrev Ben Hutchison <
brhut...@gmail.com>:
> Thanks for the explanation and pointers...
>
> IMO the use of Option[T] to support filter seems a high price to pay to
> model a blocked generator in the type-system. I prefer an exception
> myself,
> for what seems an anomalous condition. Contrast with eg Traversable.head.
Is it really a high price? I think ScalaCheck's various generator
combinators hides the Option type quite well. You really shouldn't have to
see that in your code, even if you define custom generators. The current
implementation works nicely with Scala's for-comprehensions, which I don't
think exceptions would do. You can use Scala's built-in filtering with
ScalaCheck's generators:
trait A
case class B(n: Int)
case class C(s: String)
val g: Gen[String] = for {
C(s) <- Gen.oneOf(C("foo"), B("42))
} yield s
> Also, the desire to remain completely faithful to the static types in
> this
> matter is somewhat at odds with the use of Gen.Params.size, in that Gens
> of
> non-collection types still receive a size parameter and yet ignore it.
>
> An alternative design which I was playing with yesterday is to separate
> Gen
> into a GenFactory[Config, T] and a Gen[T] interface. The former used by
> code that configures a Gen (passing customizable params of type Config),
> the latter by code that consumes the Gen's value stream.
The size parameter is loosely defined, so a generator implementer could
choose to interpret it any way she likes. Non-collection types can use the
size in a meaningful way too (most data types actually have some kind size
concept). A GenFactory could be nice, but it also adds complexity.
/ Rickard
>> <
brhut...@gmail.com<javascript:>
>> > wrote:
>>
>>> Two possibly related design questions about Scalacheck that I've never
>>> understood the motivation for properly:
>>>
>>> - Why does Gen.Params include a size? Why not assume a generator can
>>> provide an infinite stream of values?
>>>
>>> - Why does Gen[T] return Option[T]? Why would a Gen usefully return
>>> None
>>> - because it's size is exceeded, or otherwise?
>>>
>>> -Ben
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups
>>> "scalacheck" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an
>>> email to
scalacheck+...@googlegroups.com <javascript:>.
>>> To post to this group, send email to
>>>
scala...@googlegroups.com<javascript:>
>>> .