nick8325 / nick8325/quickcheck
CoArbitrary1
Nobody has claimed this yet.
- Dominant language
- Haskell
- Stars
- 790
- Forks
- 130
- Avg merge
- 16h 41m
- Merged PRs (30d)
- 2
Description
We seemingly can't have a CoArbitrary1 and CoArbitrary2 typeclass in Haskell98 compatible libraries because of the lack of RankNTypes. However, this isn't necessarily an insurmountable problem. I figured out a creative way around it.
-- Name is a placeholder, and its constructor is not exported.
data Opaque = Opaque {-# UNPACK #-} !Int {-# UNPACK #-} !QCGen
-- Also no instances defined (except Typeable automatically)
-- Turn a monomorphic coarbitrary function into a polymorphic one.
-- This is the only user-accessible function which mentions Opaque.
coarbOpaque :: (a -> Gen Opaque -> Gen Opaque) -> a -> Gen c -> Gen c
coarbOpaque coa a (MkGen gen) = MkGen $ \n rng -> case unGen (coa a (MkGen Opaque)) n rng of
Opaque n' rng' -> gen n' rng'
-- And then we can use it instead of the Haskell98-unfriendly (forall x. a -> Gen x -> Gen x).
class CoArbitrary1 f where
liftCoarbitrary :: (a -> Gen Opaque -> Gen Opaque) -> f a -> Gen c -> Gen c
#ifndef NO_GENERICS
default liftCoarbitrary :: (Generic1 f, GCoArbitrary1 (Rep1 f) => (a -> Gen Opaque -> Gen Opaque) -> f a -> Gen c -> Gen c
liftCoarbitrary = genericLiftCoarbitrary
-- Include the GCoArbitrary1 class here. It's rather mechanical.
#endif
-- And the class for CoArbitrary2.
class CoArbitrary2 f where
liftCoarbitrary2 :: (a -> Gen Opaque -> Gen Opaque) -> (b -> Gen Opaque -> Gen Opaque) -> f a b -> Gen c -> Gen c
-- And instances go here.
I think we need a better name for Opaque, though.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the proposal in this issue, including the Opaque, CoArbitrary1, and CoArbitrary2 sketches; no repository files or tests are identified. Determine whether the API can support these classes while remaining Haskell98-compatible, and consider a suitable replacement name for Opaque. Done requires a decided design and maintainer agreement.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- haskell
- Domain
- testing
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 20/100