{-|
Module      : RTile
Description : Reactive tile
Copyright   : (c) Simon Archipoff, David Janin, 2016
License     : see the LICENSE file in the distribution
Maintainer  : janin@labri.fr
Stability   : experimental

This module is a bit messed up mixing reactive tiles with runtime tile...

-}

{-# OPTIONS_GHC -Wall -fno-warn-name-shadowing #-}

{-# LANGUAGE MultiParamTypeClasses,
             FlexibleInstances #-}

module Reactive.RTile where

import Tile.Atom
import Tile.QList
import Tile.Tile

-- import Duration.Lattice
import Reactive.Duration

-- * Runtime tiles

-- | ID for temporal values and delays duration.
-- Eq instance on the type v defines when two values are to be merged.
data ID v
    = ValueID v
    -- ^ Index of the (unknown) duration of an input temporal value
    | DelayID Integer
    -- ^ Index of the (unknown) duration of the delay between two bundles of temporal values
      deriving (Eq,Ord,Show)

-- | Runtime tiles duration
type RDuration d iv = Duration d (ID iv)

              
-- | Runtime tile.
type RTile d iv v = Tile (RDuration d iv) iv v

-- | Runtime QList. 
type RQList d iv v = QList (RDuration d iv) iv v
    
-- | Runtime atoms.
type RAtom d iv v = Atom (RDuration d iv) iv v

-- | Transforms a tile into a runtime tile
toRunTile :: (Num d, Ord d, Ord iv) => Tile (RDuration d iv) iv v -> RTile d iv v
toRunTile (Tile _ _ q) = Tile 0 0 (dropQ 0 q)

-- | Transforms a runtime tile into a tile
fromRunTile :: (Num d, Ord d, Ord iv) => RTile d iv v -> Tile (RDuration d iv) iv v
fromRunTile (Tile _ _ q) = Tile 0 0 q