Skip to content

Considerations #1

@stephencelis

Description

@stephencelis

Started down the rabbit hole of deriving arbitrary instances using Codable and ended up with this repo. A few things I learned along the way:

  • PureScript has a MonadGen type class described in purescript-gen, which purescript-quickcheck uses internally. Generators on their own seem useful, so maybe a "swift-gen" library should be extracted from some of this code.

  • Gen<A> is, for now, a type alias for the State monad. We probably wanna extract the latter into some kinda "swift-control" lib.

  • Arbitrary seems to be less useful out-of-the-box? purescript-quickcheck may remove support, while another interesting PureScript property testing library omits it entirely:

    Jack doesn't have an Arbitrary type class, by design. Arbitrary instances often end up being orphans and I consider this problematic, especially in PureScript. The main purpose of the Arbitrary class as I see it is to link the generator with a shrink function, this isn't required with Jack so Arbitrary has been eliminated.

    (Could be fun to see if this automated shrinking is possible!)

  • This library implements a very bare-bones NonEmpty. We probably want a "swift-nonempty" sometime soon, and maybe this version would suffice (we use it more as a type requirement than a compositional unit, so it's tough to say when and how we'll want to add things like map, etc.).

  • It was fun to recreate this linear congruential generator! Very little code for functionally pure randomization!

  • There are one or two places where I had to optimize in a non-functional manner 😬. These could be fixed if we had TCO.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions