3 ms·
> In Haskell, the type system--thanks to typeclasses--can figure out how to generate random inputs automatically, just based on what type is expected. No. The
by laureny 13y ago
> In Haskell, the type system--thanks to typeclasses--can figure out how to generate random inputs automatically, just based on what type is expected.
No. The reason why the type system is able to generate these values is because of algebraic data types, not type classes.
Type classes are completely unrelated to this problem.
- tikhonj 13y agoWhat? The way the Arbitrary class works is only possible thanks to typeclasses. Without typeclasses, you would have to explicitly specify which generator to use. Thanks to the typeclass system, Haskell can just infer this. On the other hand, none of the Arbitrary machinery is particularly tied to algebraic data types per se. It would work as well if you had OO style constructors instead. Just take a look at the OCaml version of QuickCheck to see what I mean. OCaml obviously has algebraic data types, but it's still far more awkward to use QuickCheck there.