Created
May 8, 2014 17:40
-
-
Save pminten/27b7c7320b11c44dc562 to your computer and use it in GitHub Desktop.
Using the ClassLaws lib for a trivial example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE TypeFamilies #-} | |
{-# LANGUAGE EmptyDataDecls #-} | |
module Main where | |
import Test.ClassLaws | |
data EqLaw1 a | |
class Eq a => EqLaws a where | |
eqLaw1 :: Law (EqLaw1 a) | |
eqLaw1 (x, y) = (x == y) =.= not (x /= y) | |
type instance LawArgs (EqLaw1 a) = (a, a) | |
type instance LawBody (EqLaw1 a) = Bool | |
-- Not entirely sure why this is needed. | |
type instance Param Bool = Bool | |
instance TestEqual Int where | |
testEqual l _ = testEq (==) l | |
instance TestEqual Bool where | |
testEqual l _ = testEq (==) l | |
instance (EqLaws a, TestEqual a) => LawTest (EqLaw1 a) where | |
lawtest _ = testEqual . eqLaw1 | |
instance EqLaws Int | |
instance EqLaws Bool | |
instance EqLaws a => EqLaws [a] | |
main :: IO () | |
main = do | |
quickLawCheck (undefined :: EqLaw1 Int) | |
quickLawCheck (undefined :: EqLaw1 Bool) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment