Semigroup Result instance?

Open
#96 2 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

  • #101 by @np — closed without merging

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
25/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Domain
testing

Research direction

Read the proposed Semigroup and Monoid instances in the issue body and the linked pull request #101 for prior discussion. Decide whether combining Result values this way fits the library’s API and supports the shown QuickCheck use case; the issue does not name implementation files or tests, so locate the existing Result definitions and instances before judging completion.

Written by the indexing model from the issue text.

Description

type: enhancement

How would we feel about the following?

instance semigroupResult :: Semigroup Result where
  Success <> r = r
  Failed str <> _ = Failed str

instance monoidResult :: Monoid Result where
  mempty = Success

This is a use case I have in mind

  log "fromRotationMatrix avoids instability issues when the quaternion has one very small component"
  quickCheck \(VerySmallNum e) a b c ->
    let
      testWith p' =
        let
          p = Rotation.fromQuaternion p'
          q = unsafePartial (Rotation.fromRotationMatrix (Rotation.toRotationMatrix p))
        in
          rApproxEq p q
          <?> show { p, q }
    in
      fold
       [ testWith (Quaternion e a b c)
       , testWith (Quaternion a e b c)
       , testWith (Quaternion a b e c)
       , testWith (Quaternion a b c e)
       ]

Of course I could rewrite this test to call quickCheck four times instead, but I think the instance makes sense, and I think it would be nice to allow writing tests this way. Additionally, if generating random values for a given type is expensive, being able to combine Result values in this way could let you cut down the number of random values you need to generate, since you don't need to call quickCheck as many times.

Dominant language
PureScript
Stars
108
Forks
42
Avg merge
2d 23h
Merged PRs (30d)
1

Getting set up

  • No Dockerfile or Docker Compose file
  • Has a pull request template
  • No contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from purescript/purescript-quickcheck

All issues in purescript/purescript-quickcheck

Similar issues

More Testing & QA issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.