Skip to content

Instantly share code, notes, and snippets.

@pminten
Created May 8, 2014 17:40
Show Gist options
  • Save pminten/27b7c7320b11c44dc562 to your computer and use it in GitHub Desktop.
Save pminten/27b7c7320b11c44dc562 to your computer and use it in GitHub Desktop.
Using the ClassLaws lib for a trivial example
{-# 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