{-# LANGUAGE MultiParamTypeClasses #-}
module DES where
-- Typeclasses for sending and receiving events
class EventSender a e where
send :: a -> e
class EventRecipient a e where
receive :: a -> e -> a
-- Basic types: players and tables. These can be added to.
data Player = Player String
data Table = Table Int Player
-- Types of events: these can be added to.
data PlayerEvent = PlayerEvent Player
data OtherTableEvent = OtherTableEvent Table
data BallsAtRestEvent = BallsAtRestEvent
-- Players can send player events
instance EventSender Player PlayerEvent where
send p = PlayerEvent p
-- Players can receive balls at rest events
instance EventRecipient Player BallsAtRestEvent where
receive p _ = p -- TODO
-- Tables can receive player events
instance EventRecipient Table PlayerEvent where
receive t _ = t -- TODO
-- Tables can send other table events
instance EventSender Table OtherTableEvent where
send t = OtherTableEvent t
-- Tables can receive other table events
instance EventRecipient Table OtherTableEvent where
receive t _ = t -- TODO
-- Now we combine two tables
data TableSystem = TableSystem (Table, Table)
-- The combined system only receives player events, and sends no events
instance EventRecipient TableSystem PlayerEvent where
receive ts _ = ts -- TODO