Skip to content

Instantly share code, notes, and snippets.

@amitaibu
Created March 14, 2016 20:27
Show Gist options
  • Save amitaibu/7eb4e6798347a1dd353f to your computer and use it in GitHub Desktop.
Save amitaibu/7eb4e6798347a1dd353f to your computer and use it in GitHub Desktop.
module Example where
import Data.Semigroup
import Test.QuickCheck
data Trivial = Trivial deriving (Eq, Show)
instance Semigroup Trivial where
_ <> _ = Trivial
instance Arbitrary Trivial where
arbitrary = return Trivial
newtype Identity a = Identity a deriving (Eq, Show)
instance Semigroup (Identity a) where
x <> y = x
instance (Num a) => Arbitrary (Identity a) where
arbitrary = undefined
newtype BoolConj = BoolConj Bool deriving (Eq, Show)
instance Semigroup BoolConj where
BoolConj x <> BoolConj y = BoolConj $ x || y
instance Arbitrary BoolConj where
arbitrary = elements [BoolConj True, BoolConj False]
semigroupAssoc :: (Eq m, Semigroup m) => m -> m -> m -> Bool
semigroupAssoc a b c = (a <> (b <> c)) == ((a <> b) <> c)
type TrivialAssoc = Trivial -> Trivial -> Trivial -> Bool
type BoolConjAssoc = BoolConj -> BoolConj -> BoolConj -> Bool
main :: IO ()
main = do
quickCheck (semigroupAssoc :: TrivialAssoc)
-- @todo:
-- quickCheck (semigroupAssoc :: Identity Int -> Identity Int -> Identity Int -> Bool)
quickCheck (semigroupAssoc :: BoolConjAssoc)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment