-
Notifications
You must be signed in to change notification settings - Fork 75
Expand file tree
/
Copy pathTemporal.hs
More file actions
41 lines (36 loc) · 1.53 KB
/
Temporal.hs
File metadata and controls
41 lines (36 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
-- Copyright © 2011 National Institute of Aerospace / Galois, Inc.
{-# LANGUAGE Safe #-}
-- | Temporal stream transformations.
module Copilot.Language.Operators.Temporal
( (++)
, drop
) where
import Copilot.Core (Typed)
import Copilot.Language.Prelude
import Copilot.Language.Stream
import Prelude ((==))
infixr 1 ++
-- | Prepend a fixed number of samples to a stream.
--
-- The elements to be appended at the beginning of the stream must be limited,
-- that is, the list must have finite length.
--
-- Prepending elements to a stream may increase the memory requirements of the
-- generated programs (which now must hold the same number of elements in
-- memory for future processing).
(++) :: Typed a => [a] -> Stream a -> Stream a
(++) = (`Append` Nothing)
-- | Drop a number of samples from a stream.
--
-- The elements must be realizable at the present time to be able to drop
-- elements. For most kinds of streams, you cannot drop elements without
-- prepending an equal or greater number of elements to them first, as it
-- could result in undefined samples.
drop :: (Typed a) => Int -> Stream a -> Stream a
drop 0 s = s
-- Along with simplifying the Stream, this also avoids the invalid C code
-- generated from append (array) and drop (indexing) when their lengths are the same
drop i ( Append a _ s ) | i == length a = s
drop _ ( Const j ) = Const j
drop i ( Drop j s ) = Drop (fromIntegral i + j) s
drop i s = Drop (fromIntegral i) s