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

-- | if-then-else.

{-# LANGUAGE Safe #-}

module Copilot.Language.Operators.Mux
  ( mux
  , ifThenElse
  ) where

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

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

mux :: Typed a => Stream Bool -> Stream a -> Stream a -> Stream a
mux :: Stream Bool -> Stream a -> Stream a -> Stream a
mux (Const Bool
True) Stream a
t Stream a
_  = Stream a
t
mux (Const Bool
False) Stream a
_ Stream a
f = Stream a
f
mux Stream Bool
b Stream a
t Stream a
f             = Op3 Bool a a a -> Stream Bool -> Stream a -> Stream a -> Stream a
forall a b c d.
(Typed a, Typed b, Typed c, Typed d) =>
Op3 a b c d -> Stream a -> Stream b -> Stream c -> Stream d
Op3 (Type a -> Op3 Bool a a a
forall b. Type b -> Op3 Bool b b b
Core.Mux Type a
forall a. Typed a => Type a
typeOf) Stream Bool
b Stream a
t Stream a
f

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

ifThenElse :: Typed a => Stream Bool -> Stream a -> Stream a -> Stream a
ifThenElse :: Stream Bool -> Stream a -> Stream a -> Stream a
ifThenElse = Stream Bool -> Stream a -> Stream a -> Stream a
forall a.
Typed a =>
Stream Bool -> Stream a -> Stream a -> Stream a
mux

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