On Aug 24, 2011, at 8:44 PM, Andrew Pennebaker wrote: > Aye, it's a bit awkward, but I know that Haskell can do it because that's how > Haskell's QuickCheck library works. It even goes one step further and creates > the appropriate list of value generators according to the predicate's type.
Perhaps you could do something similar in Factor. Instead of using generator functions, you could make a single generic function that lets types describe how to generate arbitrary members of themselves: GENERIC: something-like ( exemplar -- arbitrary ) ERROR: don't-know-how-to-make-something-like exemplar ; M: object something-like don't-know-how-to-make-something-like ; M: integer something-like 2 64 ^ random ; M: float something-like -1.0 1.0 uniform-random-float ; Then pass an exemplar of the type to something-like: ( scratchpad ) 1 something-like . 16789018172707 ( scratchpad ) 1.0 something-like . -0.13980920020477 Union types and tuple types could then naturally implement something-like in terms of their constituent types. -Joe
smime.p7s
Description: S/MIME cryptographic signature
------------------------------------------------------------------------------ EMC VNX: the world's simplest storage, starting under $10K The only unified storage solution that offers unified management Up to 160% more powerful than alternatives and 25% more efficient. Guaranteed. http://p.sf.net/sfu/emc-vnx-dev2dev
_______________________________________________ Factor-talk mailing list Factor-talk@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/factor-talk