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

Define the Eq and Ord instances for the Event type by hand. #890

Open
wants to merge 1 commit into
base: 2.0-beatmode-retired
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/Sound/Tidal/Pattern.hs
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,16 @@ data EventF a b = Event
, whole :: Maybe a
, part :: a
, value :: b
} deriving (Eq, Ord, Functor, Generic)
} deriving (Functor, Generic)

instance (Eq a, Eq b) => Eq (EventF a b) where
(==) x y = let relevant e = (whole e, part e, value e)
in relevant x == relevant y

instance (Ord a, Ord b) => Ord (EventF a b) where
(<=) x y = let relevant e = (whole e, part e, value e)
in relevant x <= relevant y

instance (NFData a, NFData b) => NFData (EventF a b)

type Event a = EventF (ArcF Time) a
Expand Down
19 changes: 19 additions & 0 deletions test/Sound/Tidal/PatternTest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,25 @@ run =
let res = fmap (+1) (Arc 3 5)
property $ ((Arc 4 6) :: Arc) === res

describe "the Event type's" $ do
let e = Event { context = Context []
, whole = Just 0
, part = 0
, value = 0 }
f = e { context = Context $ [((1,1),(1,1))] }
describe "Eq instance" $
and [ e == f
, e /= e { whole = Just 1 }
, e /= e { part = 1 }
, e /= e { value = 1 } ]
describe "Ord instance" $
and [ e < f { whole = Just 1 }
, f < e { whole = Just 1 }
, e < f { part = 1 }
, f < e { part = 1 }
, e < f { value = 1 }
, f < e { value = 1 } ]

{-
describe "Event" $ do
it "(Bifunctor) first: Apply a function to the Arc elements: whole and part" $ do
Expand Down