nick8325 / quickspec

Equational laws for free
BSD 3-Clause "New" or "Revised" License
250 stars 24 forks source link

Implement a QuickCheck printer #44

Closed isovector closed 4 years ago

isovector commented 4 years ago

This PR adds a withPrintStyle signature that changes how laws are presented. Given this signature:

main :: IO ()
main = quickSpec
  [ withPrintStyle ForQuickCheck
  , con "+" ((+) :: Int -> Int -> Int)
  ]

its output becomes:

== Functions ==                  
(+) :: Int -> Int -> Int

== Laws ==
quickspec_laws :: [(String, Property)]
quickspec_laws =
  [ ( "x + y = y + x"            
    , property $
        \ (x :: Int) (y :: Int) -> (x + y) === (y + x))
  , ( "(x + y) + z = x + (y + z)"
    , property $
        \ (x :: Int) (y :: Int) (z :: Int) ->
            ((x + y) + z) === (x + (y + z)))
  ]

Laws that require use of the Observe typeclass have their properties emitted using the new (=~=) :: (Show test, Show outcome, Observe test outcome a) => a -> a -> Property operator.

Fixes #43

nick8325 commented 4 years ago

Thanks a lot!