{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE MultiParamTypeClasses #-}
module FULE.Reactor
( Reaction(..)
, Reactor
, reactor
, Reactor'
, reactor'
) where
import Control.DeepSeq
import FULE.Component
class Reaction r i ogadt where
addReactant :: i -> ogadt o -> r -> r
addReactant i
_ ogadt o
_ = r -> r
forall a. a -> a
id
getProduct :: i -> ogadt o -> r -> Maybe o
getProduct i
_ ogadt o
_ r
_ = Maybe o
forall a. Maybe a
Nothing
data Reactor i ogadt m =
forall r . (Component r m, Reaction r i ogadt) => Reactor r
instance (Monad m) => Component (Reactor i ogadt m) m where
requiredWidth :: Reactor i ogadt m -> m (Maybe Int)
requiredWidth (Reactor r
r) = r -> m (Maybe Int)
forall k (m :: * -> *). Component k m => k -> m (Maybe Int)
requiredWidth r
r
requiredHeight :: Reactor i ogadt m -> m (Maybe Int)
requiredHeight (Reactor r
r) = r -> m (Maybe Int)
forall k (m :: * -> *). Component k m => k -> m (Maybe Int)
requiredHeight r
r
instance Reaction (Reactor i ogadt m) i ogadt where
addReactant :: forall o. i -> ogadt o -> Reactor i ogadt m -> Reactor i ogadt m
addReactant i
i ogadt o
ogadt (Reactor r
r) = r -> Reactor i ogadt m
forall i (ogadt :: * -> *) (m :: * -> *) r.
(Component r m, Reaction r i ogadt) =>
r -> Reactor i ogadt m
Reactor (i -> ogadt o -> r -> r
forall o. i -> ogadt o -> r -> r
forall r i (ogadt :: * -> *) o.
Reaction r i ogadt =>
i -> ogadt o -> r -> r
addReactant i
i ogadt o
ogadt r
r)
getProduct :: forall o. i -> ogadt o -> Reactor i ogadt m -> Maybe o
getProduct i
i ogadt o
ogadt (Reactor r
r) = i -> ogadt o -> r -> Maybe o
forall o. i -> ogadt o -> r -> Maybe o
forall r i (ogadt :: * -> *) o.
Reaction r i ogadt =>
i -> ogadt o -> r -> Maybe o
getProduct i
i ogadt o
ogadt r
r
reactor :: (Component r m, Reaction r i ogadt) => r -> Reactor i ogadt m
reactor :: forall r (m :: * -> *) i (ogadt :: * -> *).
(Component r m, Reaction r i ogadt) =>
r -> Reactor i ogadt m
reactor = r -> Reactor i ogadt m
forall i (ogadt :: * -> *) (m :: * -> *) r.
(Component r m, Reaction r i ogadt) =>
r -> Reactor i ogadt m
Reactor
data Reactor' i ogadt m =
forall r . (Component r m, NFData r, Reaction r i ogadt) => Reactor' !r
instance (Monad m) => Component (Reactor' i ogadt m) m where
requiredWidth :: Reactor' i ogadt m -> m (Maybe Int)
requiredWidth (Reactor' r
r) = r -> m (Maybe Int)
forall k (m :: * -> *). Component k m => k -> m (Maybe Int)
requiredWidth r
r
requiredHeight :: Reactor' i ogadt m -> m (Maybe Int)
requiredHeight (Reactor' r
r) = r -> m (Maybe Int)
forall k (m :: * -> *). Component k m => k -> m (Maybe Int)
requiredHeight r
r
instance NFData (Reactor' i ogadt m) where
rnf :: Reactor' i ogadt m -> ()
rnf (Reactor' r
r) = r -> ()
forall a. NFData a => a -> ()
rnf r
r
instance Reaction (Reactor' i ogadt m) i ogadt where
addReactant :: forall o. i -> ogadt o -> Reactor' i ogadt m -> Reactor' i ogadt m
addReactant i
i ogadt o
ogadt (Reactor' r
r) = r -> Reactor' i ogadt m
forall i (ogadt :: * -> *) (m :: * -> *) r.
(Component r m, NFData r, Reaction r i ogadt) =>
r -> Reactor' i ogadt m
Reactor' (i -> ogadt o -> r -> r
forall o. i -> ogadt o -> r -> r
forall r i (ogadt :: * -> *) o.
Reaction r i ogadt =>
i -> ogadt o -> r -> r
addReactant i
i ogadt o
ogadt r
r)
getProduct :: forall o. i -> ogadt o -> Reactor' i ogadt m -> Maybe o
getProduct i
i ogadt o
ogadt (Reactor' r
r) = i -> ogadt o -> r -> Maybe o
forall o. i -> ogadt o -> r -> Maybe o
forall r i (ogadt :: * -> *) o.
Reaction r i ogadt =>
i -> ogadt o -> r -> Maybe o
getProduct i
i ogadt o
ogadt r
r
reactor' :: (Component r m, NFData r, Reaction r i ogadt) => r -> Reactor' i ogadt m
reactor' :: forall r (m :: * -> *) i (ogadt :: * -> *).
(Component r m, NFData r, Reaction r i ogadt) =>
r -> Reactor' i ogadt m
reactor' = r -> Reactor' i ogadt m
forall i (ogadt :: * -> *) (m :: * -> *) r.
(Component r m, NFData r, Reaction r i ogadt) =>
r -> Reactor' i ogadt m
Reactor'