--------------------------------------------------------------------------------
-- Copyright © 2011 National Institute of Aerospace / Galois, Inc.
--------------------------------------------------------------------------------

{-# LANGUAGE Safe #-}

-- | Equality applied point-wise on streams.
module Copilot.Language.Operators.Eq
  ( (==)
  , (/=)
  ) where

import Copilot.Core (Typed, typeOf)
import qualified Copilot.Core as Core
import Copilot.Language.Prelude
import Copilot.Language.Stream
import qualified Prelude as P

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

-- | Compare two streams point-wise for equality.
--
-- The output stream contains the value True at a point in time if both
-- argument streams contain the same value at that point in time.
(==) :: (P.Eq a, Typed a) => Stream a -> Stream a -> Stream Bool
(Const a
x) == :: Stream a -> Stream a -> Stream Bool
== (Const a
y) = Bool -> Stream Bool
forall a. Typed a => a -> Stream a
Const (a
x a -> a -> Bool
forall a. Eq a => a -> a -> Bool
P.== a
y)
Stream a
x == Stream a
y = Op2 a a Bool -> Stream a -> Stream a -> Stream Bool
forall a b c.
(Typed a, Typed b, Typed c) =>
Op2 a b c -> Stream a -> Stream b -> Stream c
Op2 (Type a -> Op2 a a Bool
forall a. Eq a => Type a -> Op2 a a Bool
Core.Eq Type a
forall a. Typed a => Type a
typeOf) Stream a
x Stream a
y

-- | Compare two streams point-wise for inequality.
--
-- The output stream contains the value True at a point in time if both
-- argument streams contain different values at that point in time.
(/=) :: (P.Eq a, Typed a) => Stream a -> Stream a -> Stream Bool
(Const a
x) /= :: Stream a -> Stream a -> Stream Bool
/= (Const a
y) = Bool -> Stream Bool
forall a. Typed a => a -> Stream a
Const (a
x a -> a -> Bool
forall a. Eq a => a -> a -> Bool
P./= a
y)
Stream a
x /= Stream a
y = Op2 a a Bool -> Stream a -> Stream a -> Stream Bool
forall a b c.
(Typed a, Typed b, Typed c) =>
Op2 a b c -> Stream a -> Stream b -> Stream c
Op2 (Type a -> Op2 a a Bool
forall a. Eq a => Type a -> Op2 a a Bool
Core.Ne Type a
forall a. Typed a => Type a
typeOf) Stream a
x Stream a
y

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