{-# LANGUAGE TypeFamilies, FlexibleInstances, GADTs, StandaloneDeriving #-}
{-# OPTIONS_HADDOCK hide #-}
-----------------------------------------------------------------------------
-- |
-- Module      :  ForSyDe.Atom.MoC.DE.Core
-- Copyright   :  (c) George Ungureanu, KTH/ICT/ESY 2016
-- License     :  BSD-style (see the file LICENSE)
-- 
-- Maintainer  :  ugeorge@kth.se
-- Stability   :  experimental
-- Portability :  portable
--
-- This module implements the core semantics of the DE MoC.
 
-----------------------------------------------------------------------------

module ForSyDe.Atom.MoC.DE.Core where

import ForSyDe.Atom.MoC
import ForSyDe.Atom.MoC.TimeStamp
import ForSyDe.Atom.Utility.Tuple (($$),($$$),($$$$))

import Prelude hiding (until)


-- | Type synonym for a base DE signal as a stream of 'DE' events, where the type of
-- tags has not been determined yet. In designs, it is advised to define a type alias
-- for signals, using an appropriate numerical type for tags, e.g.
--
-- > import ForSyDe.Atom.MoC.DE hiding (Signal) -- hide provided alias, to use your own
-- >
-- > type Signal a = SignalBase Int a
type SignalBase t a = Stream (DE t a)

-- | Convenience alias for a DE signal, where tags are represented using our exported
-- 'TimeStamp' type.
type Signal a = SignalBase TimeStamp a

-- | The DE event. It identifies a discrete event signal. The type of the tag system
-- needs to satisfy all of the three properties, as suggested by the type constraints
-- imposed on it:
--
-- * it needs to be a numerical type, to express value 0 (global start) and every
--   representable number needs to have an additive inverse.
--
-- * it needs to be unambiguously comparable (defines a total order).
--
-- * it needs to unambiguously define an equality operation.
--
-- Due to these properties not all numerical types can represent DE tags. A typical
-- example of inappropriate representation is 'Float'.
data DE t a where
  DE :: (Num t, Ord t, Eq t)
     => { DE t a -> t
tag :: t,  -- ^ timestamp
          DE t a -> a
val :: a   -- ^ the value
        } -> DE t a
deriving instance (Num t, Ord t, Eq t, Eq t, Eq a) => Eq (DE t a)

-- | Implenents the execution semantics for the DE MoC atoms.
instance (Num t, Ord t, Eq t) => MoC (DE t) where
  type Fun (DE t) a b = a -> b
  type Ret (DE t) b   = b 
  ---------------------
  -.- :: Fun (DE t) a b -> Stream (DE t a) -> Stream (DE t b)
(-.-) = (DE t a -> DE t b) -> Stream (DE t a) -> Stream (DE t b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((DE t a -> DE t b) -> Stream (DE t a) -> Stream (DE t b))
-> ((a -> b) -> DE t a -> DE t b)
-> (a -> b)
-> Stream (DE t a)
-> Stream (DE t b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> b) -> DE t a -> DE t b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap
  ---------------------
  _       -*- :: Stream (DE t (Fun (DE t) a b))
-> Stream (DE t a) -> Stream (DE t b)
-*- NullS   = Stream (DE t b)
forall e. Stream e
NullS
  NullS   -*- _       = Stream (DE t b)
forall e. Stream e
NullS
  (f :: DE t (Fun (DE t) a b)
f:-fs :: Stream (DE t (Fun (DE t) a b))
fs) -*- (x :: DE t a
x:-xs :: Stream (DE t a)
xs)               =      DE t (Fun (DE t) a b)
DE t (a -> b)
f  DE t (a -> b) -> DE t a -> DE t b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> DE t a
x  DE t b -> Stream (DE t b) -> Stream (DE t b)
forall e. e -> Stream e -> Stream e
:- DE t (a -> b)
-> DE t a
-> Stream (DE t (a -> b))
-> Stream (DE t a)
-> Stream (DE t b)
forall t a b.
(Num t, Ord t) =>
DE t (a -> b)
-> DE t a
-> Stream (DE t (a -> b))
-> Stream (DE t a)
-> Stream (DE t b)
comb DE t (Fun (DE t) a b)
DE t (a -> b)
f  DE t a
x  Stream (DE t (Fun (DE t) a b))
Stream (DE t (a -> b))
fs Stream (DE t a)
xs
    where comb :: DE t (a -> b)
-> DE t a
-> Stream (DE t (a -> b))
-> Stream (DE t a)
-> Stream (DE t b)
comb pf :: DE t (a -> b)
pf px :: DE t a
px s1 :: Stream (DE t (a -> b))
s1@(f :: DE t (a -> b)
f :- fs :: Stream (DE t (a -> b))
fs) s2 :: Stream (DE t a)
s2@(x :: DE t a
x :- xs :: Stream (DE t a)
xs)
            | DE t (a -> b) -> t
forall t a. DE t a -> t
tag DE t (a -> b)
f t -> t -> Bool
forall a. Eq a => a -> a -> Bool
== DE t a -> t
forall t a. DE t a -> t
tag DE t a
x        = DE t (a -> b)
f DE t (a -> b) -> DE t (a -> b) -> DE t (a -> b)
forall t a t a. DE t a -> DE t a -> DE t a
%> DE t (a -> b)
f  DE t (a -> b) -> DE t a -> DE t b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> DE t a
x  DE t b -> Stream (DE t b) -> Stream (DE t b)
forall e. e -> Stream e -> Stream e
:- DE t (a -> b)
-> DE t a
-> Stream (DE t (a -> b))
-> Stream (DE t a)
-> Stream (DE t b)
comb DE t (a -> b)
f  DE t a
x  Stream (DE t (a -> b))
fs Stream (DE t a)
xs
            | DE t (a -> b) -> t
forall t a. DE t a -> t
tag DE t (a -> b)
f t -> t -> Bool
forall a. Ord a => a -> a -> Bool
<  DE t a -> t
forall t a. DE t a -> t
tag DE t a
x        = DE t (a -> b)
f DE t (a -> b) -> DE t (a -> b) -> DE t (a -> b)
forall t a t a. DE t a -> DE t a -> DE t a
%> DE t (a -> b)
f  DE t (a -> b) -> DE t a -> DE t b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> DE t a
px DE t b -> Stream (DE t b) -> Stream (DE t b)
forall e. e -> Stream e -> Stream e
:- DE t (a -> b)
-> DE t a
-> Stream (DE t (a -> b))
-> Stream (DE t a)
-> Stream (DE t b)
comb DE t (a -> b)
f  DE t a
px Stream (DE t (a -> b))
fs Stream (DE t a)
s2
            | DE t (a -> b) -> t
forall t a. DE t a -> t
tag DE t (a -> b)
f t -> t -> Bool
forall a. Ord a => a -> a -> Bool
>  DE t a -> t
forall t a. DE t a -> t
tag DE t a
x        = DE t a
x DE t a -> DE t (a -> b) -> DE t (a -> b)
forall t a t a. DE t a -> DE t a -> DE t a
%> DE t (a -> b)
pf DE t (a -> b) -> DE t a -> DE t b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> DE t a
x  DE t b -> Stream (DE t b) -> Stream (DE t b)
forall e. e -> Stream e -> Stream e
:- DE t (a -> b)
-> DE t a
-> Stream (DE t (a -> b))
-> Stream (DE t a)
-> Stream (DE t b)
comb DE t (a -> b)
pf DE t a
x  Stream (DE t (a -> b))
s1 Stream (DE t a)
xs
          comb _ px :: DE t a
px (f :: DE t (a -> b)
f :- fs :: Stream (DE t (a -> b))
fs) NullS = DE t (a -> b)
f DE t (a -> b) -> DE t (a -> b) -> DE t (a -> b)
forall t a t a. DE t a -> DE t a -> DE t a
%> DE t (a -> b)
f  DE t (a -> b) -> DE t a -> DE t b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> DE t a
px DE t b -> Stream (DE t b) -> Stream (DE t b)
forall e. e -> Stream e -> Stream e
:- DE t (a -> b)
-> DE t a
-> Stream (DE t (a -> b))
-> Stream (DE t a)
-> Stream (DE t b)
comb DE t (a -> b)
f  DE t a
px Stream (DE t (a -> b))
fs Stream (DE t a)
forall e. Stream e
NullS
          comb pf :: DE t (a -> b)
pf _ NullS (x :: DE t a
x :- xs :: Stream (DE t a)
xs) = DE t a
x DE t a -> DE t (a -> b) -> DE t (a -> b)
forall t a t a. DE t a -> DE t a -> DE t a
%> DE t (a -> b)
pf DE t (a -> b) -> DE t a -> DE t b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> DE t a
x  DE t b -> Stream (DE t b) -> Stream (DE t b)
forall e. e -> Stream e -> Stream e
:- DE t (a -> b)
-> DE t a
-> Stream (DE t (a -> b))
-> Stream (DE t a)
-> Stream (DE t b)
comb DE t (a -> b)
pf DE t a
x  Stream (DE t (a -> b))
forall e. Stream e
NullS Stream (DE t a)
xs
          comb _ _ NullS NullS      = Stream (DE t b)
forall e. Stream e
NullS
  ---------------------
  -* :: Stream (DE t (Ret (DE t) b)) -> Stream (DE t b)
(-*) = Stream (DE t (Ret (DE t) b)) -> Stream (DE t b)
forall a. a -> a
id
  ---------------------
  (DE _ v :: a
v :- _) -<- :: Stream (DE t a) -> Stream (DE t a) -> Stream (DE t a)
-<- xs :: Stream (DE t a)
xs = a -> DE t a
forall (f :: * -> *) a. Applicative f => a -> f a
pure a
v DE t a -> Stream (DE t a) -> Stream (DE t a)
forall e. e -> Stream e -> Stream e
:- Stream (DE t a)
xs
  ---------------------
  (_ :- DE d :: t
d _ :- _) -&- :: Stream (DE t a) -> Stream (DE t a) -> Stream (DE t a)
-&- xs :: Stream (DE t a)
xs = (\(DE t :: t
t v :: a
v) -> t -> a -> DE t a
forall t a. (Num t, Ord t, Eq t) => t -> a -> DE t a
DE (t
t t -> t -> t
forall a. Num a => a -> a -> a
+ t
d) a
v) (DE t a -> DE t a) -> Stream (DE t a) -> Stream (DE t a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Stream (DE t a)
xs
  (_ :- NullS) -&- _  = [Char] -> Stream (DE t a)
forall a. HasCallStack => [Char] -> a
error "[MoC.DE] signal delayed to infinity"
  ---------------------

-- | Shows the event with tag @t@ and value @v@ as @v\@t@.
instance (Show a, Show t) => Show (DE t a) where
  showsPrec :: Int -> DE t a -> ShowS
showsPrec _ (DE t :: t
t x :: a
x) = [Char] -> ShowS
forall a. [a] -> [a] -> [a]
(++) ( a -> [Char]
forall a. Show a => a -> [Char]
show a
x [Char] -> ShowS
forall a. [a] -> [a] -> [a]
++ "@" [Char] -> ShowS
forall a. [a] -> [a] -> [a]
++ t -> [Char]
forall a. Show a => a -> [Char]
show t
t )

-- | Reads the string of type @v\@t@ as an event @DE t v@.
instance (Read a,Read t, Num t, Ord t, Eq t, Eq t) => Read (DE t a) where
  readsPrec :: Int -> ReadS (DE t a)
readsPrec _ x :: [Char]
x = [ (t -> a -> DE t a
forall t a. (Num t, Ord t, Eq t) => t -> a -> DE t a
DE t
tg a
val, [Char]
r2)
                  | (val :: a
val,r1 :: [Char]
r1) <- ReadS a
forall a. Read a => ReadS a
reads ReadS a -> ReadS a
forall a b. (a -> b) -> a -> b
$ (Char -> Bool) -> ShowS
forall a. (a -> Bool) -> [a] -> [a]
takeWhile (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
/='@') [Char]
x
                  , (tg :: t
tg, r2 :: [Char]
r2) <- ReadS t
forall a. Read a => ReadS a
reads ReadS t -> ReadS t
forall a b. (a -> b) -> a -> b
$ ShowS
forall a. [a] -> [a]
tail ShowS -> ShowS
forall a b. (a -> b) -> a -> b
$ (Char -> Bool) -> ShowS
forall a. (a -> Bool) -> [a] -> [a]
dropWhile (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
/='@') [Char]
x ]

-- | Allows for mapping of functions on a DE event.
instance (Num t, Ord t, Eq t) => Functor (DE t) where
  fmap :: (a -> b) -> DE t a -> DE t b
fmap f :: a -> b
f (DE t :: t
t a :: a
a) = t -> b -> DE t b
forall t a. (Num t, Ord t, Eq t) => t -> a -> DE t a
DE t
t (a -> b
f a
a)

-- | Allows for lifting functions on a pair of DE events.
instance (Num t, Ord t, Eq t) => Applicative (DE t) where
  pure :: a -> DE t a
pure = t -> a -> DE t a
forall t a. (Num t, Ord t, Eq t) => t -> a -> DE t a
DE 0
  (DE tf :: t
tf f :: a -> b
f) <*> :: DE t (a -> b) -> DE t a -> DE t b
<*> (DE _ x :: a
x) = t -> b -> DE t b
forall t a. (Num t, Ord t, Eq t) => t -> a -> DE t a
DE t
tf (a -> b
f a
x)

-----------------------------------------------------------------------------

unit  :: (Num t, Ord t, Eq t) => (t, a) -> SignalBase t a 
-- | Wraps a (tuple of) pair(s) @(tag, value)@ into the equivalent
-- unit signal(s). A unit signal is a signal with one event with the
-- period @tag@ carrying @value@.
--
-- Helpers: @unit|unit[2-4]@.
unit2 :: (Num t, Ord t, Eq t)
      => ((t,a1),(t, a2))
      -> (SignalBase t a1, SignalBase t a2)
unit3 :: (Num t, Ord t, Eq t)
      => ((t,a1),(t, a2),(t, a3))
      -> (SignalBase t a1, SignalBase t a2, SignalBase t a3)
unit4 :: (Num t, Ord t, Eq t)
      => ((t,a1),(t, a2),(t, a3),(t, a4))
      -> (SignalBase t a1, SignalBase t a2, SignalBase t a3, SignalBase t a4)
         
unit :: (t, a) -> SignalBase t a
unit (t :: t
t,v :: a
v) = (t -> a -> DE t a
forall t a. (Num t, Ord t, Eq t) => t -> a -> DE t a
DE 0 a
v DE t a -> SignalBase t a -> SignalBase t a
forall e. e -> Stream e -> Stream e
:- t -> a -> DE t a
forall t a. (Num t, Ord t, Eq t) => t -> a -> DE t a
DE t
t a
v DE t a -> SignalBase t a -> SignalBase t a
forall e. e -> Stream e -> Stream e
:- SignalBase t a
forall e. Stream e
NullS)
unit2 :: ((t, a1), (t, a2)) -> (SignalBase t a1, SignalBase t a2)
unit2 = ((t, a1) -> SignalBase t a1, (t, a2) -> SignalBase t a2)
-> ((t, a1), (t, a2)) -> (SignalBase t a1, SignalBase t a2)
forall a1 b1 a2 b2. (a1 -> b1, a2 -> b2) -> (a1, a2) -> (b1, b2)
($$) ((t, a1) -> SignalBase t a1
forall t a. (Num t, Ord t, Eq t) => (t, a) -> SignalBase t a
unit,(t, a2) -> SignalBase t a2
forall t a. (Num t, Ord t, Eq t) => (t, a) -> SignalBase t a
unit)
unit3 :: ((t, a1), (t, a2), (t, a3))
-> (SignalBase t a1, SignalBase t a2, SignalBase t a3)
unit3 = ((t, a1) -> SignalBase t a1, (t, a2) -> SignalBase t a2,
 (t, a3) -> SignalBase t a3)
-> ((t, a1), (t, a2), (t, a3))
-> (SignalBase t a1, SignalBase t a2, SignalBase t a3)
forall t1 a t2 b t3 c.
(t1 -> a, t2 -> b, t3 -> c) -> (t1, t2, t3) -> (a, b, c)
($$$) ((t, a1) -> SignalBase t a1
forall t a. (Num t, Ord t, Eq t) => (t, a) -> SignalBase t a
unit,(t, a2) -> SignalBase t a2
forall t a. (Num t, Ord t, Eq t) => (t, a) -> SignalBase t a
unit,(t, a3) -> SignalBase t a3
forall t a. (Num t, Ord t, Eq t) => (t, a) -> SignalBase t a
unit)
unit4 :: ((t, a1), (t, a2), (t, a3), (t, a4))
-> (SignalBase t a1, SignalBase t a2, SignalBase t a3,
    SignalBase t a4)
unit4 = ((t, a1) -> SignalBase t a1, (t, a2) -> SignalBase t a2,
 (t, a3) -> SignalBase t a3, (t, a4) -> SignalBase t a4)
-> ((t, a1), (t, a2), (t, a3), (t, a4))
-> (SignalBase t a1, SignalBase t a2, SignalBase t a3,
    SignalBase t a4)
forall t1 a t2 b t3 c t4 d.
(t1 -> a, t2 -> b, t3 -> c, t4 -> d)
-> (t1, t2, t3, t4) -> (a, b, c, d)
($$$$) ((t, a1) -> SignalBase t a1
forall t a. (Num t, Ord t, Eq t) => (t, a) -> SignalBase t a
unit,(t, a2) -> SignalBase t a2
forall t a. (Num t, Ord t, Eq t) => (t, a) -> SignalBase t a
unit,(t, a3) -> SignalBase t a3
forall t a. (Num t, Ord t, Eq t) => (t, a) -> SignalBase t a
unit,(t, a4) -> SignalBase t a4
forall t a. (Num t, Ord t, Eq t) => (t, a) -> SignalBase t a
unit)

-- | Creates an infinite signal.
infinite :: (Num t, Ord t, Eq t) => a -> SignalBase t a
infinite :: a -> SignalBase t a
infinite v :: a
v = t -> a -> DE t a
forall t a. (Num t, Ord t, Eq t) => t -> a -> DE t a
DE 0 a
v DE t a -> SignalBase t a -> SignalBase t a
forall e. e -> Stream e -> Stream e
:- SignalBase t a
forall e. Stream e
NullS

-- | Transforms a list of tuples @(tag, value)@ into a DE
-- signal. Checks if it is well-formed.
signal :: (Num t, Ord t, Eq t) => [(t, a)] -> SignalBase t a
signal :: [(t, a)] -> SignalBase t a
signal = SignalBase t a -> SignalBase t a
forall t a. (Num t, Ord t) => Stream (DE t a) -> Stream (DE t a)
checkSignal (SignalBase t a -> SignalBase t a)
-> ([(t, a)] -> SignalBase t a) -> [(t, a)] -> SignalBase t a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [DE t a] -> SignalBase t a
forall a. [a] -> Stream a
stream ([DE t a] -> SignalBase t a)
-> ([(t, a)] -> [DE t a]) -> [(t, a)] -> SignalBase t a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((t, a) -> DE t a) -> [(t, a)] -> [DE t a]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\(t :: t
t, v :: a
v) -> t -> a -> DE t a
forall t a. (Num t, Ord t, Eq t) => t -> a -> DE t a
DE t
t a
v)

-- | Takes the first part of the signal util a given timestamp. The
-- last event of the resulting signal is at the given timestamp and
-- carries the previous value. This utility is useful when plotting
-- a signal, to specify the interval of plotting.
until :: (Num t, Ord t, Eq t) => t -> SignalBase t a -> SignalBase t a
until :: t -> SignalBase t a -> SignalBase t a
until _ NullS = SignalBase t a
forall e. Stream e
NullS
until u :: t
u (DE t :: t
t v :: a
v:-NullS)
  | t
t t -> t -> Bool
forall a. Ord a => a -> a -> Bool
< t
u     = t -> a -> DE t a
forall t a. (Num t, Ord t, Eq t) => t -> a -> DE t a
DE t
t a
v DE t a -> SignalBase t a -> SignalBase t a
forall e. e -> Stream e -> Stream e
:- t -> a -> DE t a
forall t a. (Num t, Ord t, Eq t) => t -> a -> DE t a
DE t
u a
v DE t a -> SignalBase t a -> SignalBase t a
forall e. e -> Stream e -> Stream e
:- SignalBase t a
forall e. Stream e
NullS
  | Bool
otherwise = t -> a -> DE t a
forall t a. (Num t, Ord t, Eq t) => t -> a -> DE t a
DE t
u a
v DE t a -> SignalBase t a -> SignalBase t a
forall e. e -> Stream e -> Stream e
:- SignalBase t a
forall e. Stream e
NullS
until u :: t
u (DE t :: t
t v :: a
v:-xs :: SignalBase t a
xs)
  | t
t t -> t -> Bool
forall a. Ord a => a -> a -> Bool
< t
u     = t -> a -> DE t a
forall t a. (Num t, Ord t, Eq t) => t -> a -> DE t a
DE t
t a
v DE t a -> SignalBase t a -> SignalBase t a
forall e. e -> Stream e -> Stream e
:- t -> SignalBase t a -> SignalBase t a
forall t a.
(Num t, Ord t, Eq t) =>
t -> SignalBase t a -> SignalBase t a
until t
u SignalBase t a
xs
  | Bool
otherwise = t -> a -> DE t a
forall t a. (Num t, Ord t, Eq t) => t -> a -> DE t a
DE t
u a
v DE t a -> SignalBase t a -> SignalBase t a
forall e. e -> Stream e -> Stream e
:- SignalBase t a
forall e. Stream e
NullS

-- | Reads a signal from a string and checks if it is well-formed.
-- Like with the @read@ function from @Prelude@, you must specify the
-- type of the signal.
--
-- >>> readSignal "{ 1@0, 2@2, 3@5, 4@7, 5@10 }" :: Signal Int
-- {1@0s,2@2s,3@5s,4@7s,5@10s}
--
-- Incorrect usage (not covered by @doctest@):
--
-- > λ> readSignal "{ 1@0, 2@2, 3@5, 4@10, 5@7 }" :: Signal Int
-- > {1@0s,2@2s,3@5s*** Exception: [MoC.DE] malformed signal
-- > λ> readSignal "{ 1@1, 2@2, 3@5, 4@7, 5@10 }" :: Signal Int
-- > *** Exception: [MoC.DE] signal does not start from global 0
readSignal :: (Num t, Ord t, Eq t, Read t, Read a) => String -> SignalBase t a
readSignal :: [Char] -> SignalBase t a
readSignal s :: [Char]
s = SignalBase t a -> SignalBase t a
forall t a. (Num t, Ord t) => Stream (DE t a) -> Stream (DE t a)
checkSignal (SignalBase t a -> SignalBase t a)
-> SignalBase t a -> SignalBase t a
forall a b. (a -> b) -> a -> b
$ [Char] -> SignalBase t a
forall a. Read a => [Char] -> a
read [Char]
s

-- | Checks if a signal is well-formed or not, according to the DE MoC
-- interpretation in ForSyDe-Atom.
checkSignal :: Stream (DE t a) -> Stream (DE t a)
checkSignal NullS = Stream (DE t a)
forall e. Stream e
NullS
checkSignal s :: Stream (DE t a)
s@(x :: DE t a
x:-_)
  | DE t a -> t
forall t a. DE t a -> t
tag DE t a
x t -> t -> Bool
forall a. Eq a => a -> a -> Bool
== 0 = Stream (DE t a) -> Stream (DE t a)
forall t a. Ord t => Stream (DE t a) -> Stream (DE t a)
checkOrder Stream (DE t a)
s
  | Bool
otherwise  = [Char] -> Stream (DE t a)
forall a. HasCallStack => [Char] -> a
error "[MoC.DE] signal does not start from global 0"
  where
    checkOrder :: Stream (DE t a) -> Stream (DE t a)
checkOrder NullS      = Stream (DE t a)
forall e. Stream e
NullS
    checkOrder (x :: DE t a
x:-NullS) = (DE t a
xDE t a -> Stream (DE t a) -> Stream (DE t a)
forall e. e -> Stream e -> Stream e
:-Stream (DE t a)
forall e. Stream e
NullS)
    checkOrder (x :: DE t a
x:-y :: DE t a
y:-xs :: Stream (DE t a)
xs) | DE t a -> t
forall t a. DE t a -> t
tag DE t a
x t -> t -> Bool
forall a. Ord a => a -> a -> Bool
< DE t a -> t
forall t a. DE t a -> t
tag DE t a
y = DE t a
x DE t a -> Stream (DE t a) -> Stream (DE t a)
forall e. e -> Stream e -> Stream e
:-Stream (DE t a) -> Stream (DE t a)
checkOrder (DE t a
yDE t a -> Stream (DE t a) -> Stream (DE t a)
forall e. e -> Stream e -> Stream e
:-Stream (DE t a)
xs)
                          | Bool
otherwise = [Char] -> Stream (DE t a)
forall a. HasCallStack => [Char] -> a
error "[MoC.DE] malformed signal"

----------------------------------------------------------------------------- 
-- These functions are not exported and are used internally.

infixl 7 %>
(DE t :: t
t _) %> :: DE t a -> DE t a -> DE t a
%> (DE _ x) = t -> a -> DE t a
forall t a. (Num t, Ord t, Eq t) => t -> a -> DE t a
DE t
t a
x

-----------------------------------------------------------------------------