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

monadLogic #57

Open
isovector opened this issue Sep 24, 2020 · 2 comments
Open

monadLogic #57

isovector opened this issue Sep 24, 2020 · 2 comments

Comments

@isovector
Copy link
Contributor

isovector commented Sep 24, 2020

I wrote the MonadLogic laws up, posting them here for posterity. Happy to open a PR if desired.

monadLogic
    :: forall m a b
     . ( CoArbitrary a
       , Arbitrary (m b)
       , Arbitrary a
       , Arbitrary (m a)
       , MonadPlus m
       , MonadLogic m
       , EqProp (m b)
       , EqProp (m (Maybe (a, m a)))
       , Show a
       , Show (m a)
       , Show (m b)
       , Function a
       )
    => m (a, b)
    -> TestBatch
monadLogic _ =
  ( "MonadLogic laws"
  , [ ("msplit mzero", msplit @m @a mzero =-= return Nothing)
    , ("msplit mplus", property $ do
        a <- arbitrary
        m <- arbitrary
        pure $
          counterexample (show a) $
          counterexample (show m) $
            msplit @m @a (return a `mplus` m) =-= return (Just (a, m))
      )
    , ("ifte return", property $ do
        a <- arbitrary
        thf <- arbitrary
        let th = applyFun thf
        el <- arbitrary
        pure $
          counterexample (show a) $
          counterexample (show thf) $
          counterexample (show el) $
            ifte @m @a @b (return a) th el =-= th a
      )
    , ("ifte mzero", property $ do
        thf <- arbitrary
        let th = applyFun thf
        el <- arbitrary @(m b)
        pure $
          counterexample (show thf) $
          counterexample (show el) $
            ifte @m @a @b mzero th el =-= el
      )
    , ("ifte mplus", property $ do
        a <- arbitrary
        m <- arbitrary
        thf <- arbitrary
        let th = applyFun thf
        el <- arbitrary @(m b)
        pure $
          counterexample (show a) $
          counterexample (show m) $
          counterexample (show thf) $
          counterexample (show el) $
            ifte @m @a @b (return a `mplus` m) th el
              =-= th a `mplus` (m >>= th)
      )
    ]
  )
@sjakobi
Copy link
Member

sjakobi commented Sep 25, 2020

I have no qualms about adding logict as a dependency, so a PR would very likely be accepted.

@isovector
Copy link
Contributor Author

We stopped needing monadlogic in our project, so there is less impetus for me to get this merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants