Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Semigroup, Monoid, and HeytingAlgebra instances to Result #101

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions src/Test/QuickCheck.purs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ import Prelude
import Control.Monad.Rec.Class (Step(..), tailRec)
import Data.Foldable (for_)
import Data.FoldableWithIndex (foldlWithIndex)
import Data.HeytingAlgebra (ff)
import Data.List (List)
import Data.List as List
import Data.Maybe (Maybe(..))
Expand Down Expand Up @@ -223,6 +224,32 @@ instance showResult :: Show Result where
show Success = "Success"
show (Failed msg) = "Failed: " <> msg

instance semigroupResult :: Semigroup Result where
append Success r = r
append (Failed str) _ = Failed str

instance monoidResult :: Monoid Result where
mempty = Success

instance heytingAlgebraResult :: HeytingAlgebra Result where
ff = Failed "ff"

tt = Success

implies (Failed _) _ = Success
implies Success x = x

conj Success x = x
conj x Success = x
conj (Failed x) (Failed y) = Failed (x <> " and " <> y)

disj Success _ = Success
disj _ Success = Success
disj (Failed x) (Failed y) = Failed (x <> " or " <> y)

not Success = ff
not (Failed _) = Success

-- | This operator attaches an error message to a failed test.
-- |
-- | For example:
Expand Down