tcalculus-1.0.0: A DSL prototype for structured realtime/reactive functional programing

Safe HaskellSafe
LanguageHaskell2010

Runtime.Multiplex

Synopsis

Documentation

data Either a b :: * -> * -> * #

The Either type represents values with two possibilities: a value of type Either a b is either Left a or Right b.

The Either type is sometimes used to represent a value which is either correct or an error; by convention, the Left constructor is used to hold an error value and the Right constructor is used to hold a correct value (mnemonic: "right" also means "correct").

Examples

The type Either String Int is the type of values which can be either a String or an Int. The Left constructor can be used only on Strings, and the Right constructor can be used only on Ints:

>>> let s = Left "foo" :: Either String Int
>>> s
Left "foo"
>>> let n = Right 3 :: Either String Int
>>> n
Right 3
>>> :type s
s :: Either String Int
>>> :type n
n :: Either String Int

The fmap from our Functor instance will ignore Left values, but will apply the supplied function to values contained in a Right:

>>> let s = Left "foo" :: Either String Int
>>> let n = Right 3 :: Either String Int
>>> fmap (*2) s
Left "foo"
>>> fmap (*2) n
Right 6

The Monad instance for Either allows us to chain together multiple actions which may fail, and fail overall if any of the individual steps failed. First we'll write a function that can either parse an Int from a Char, or fail.

>>> import Data.Char ( digitToInt, isDigit )
>>> :{
    let parseEither :: Char -> Either String Int
        parseEither c
          | isDigit c = Right (digitToInt c)
          | otherwise = Left "parse error"
>>> :}

The following should work, since both '1' and '2' can be parsed as Ints.

>>> :{
    let parseMultiple :: Either String Int
        parseMultiple = do
          x <- parseEither '1'
          y <- parseEither '2'
          return (x + y)
>>> :}
>>> parseMultiple
Right 3

But the following should fail overall, since the first operation where we attempt to parse 'm' as an Int will fail:

>>> :{
    let parseMultiple :: Either String Int
        parseMultiple = do
          x <- parseEither 'm'
          y <- parseEither '2'
          return (x + y)
>>> :}
>>> parseMultiple
Left "parse error"

Instances

Eq2 Either 

Methods

liftEq2 :: (a -> b -> Bool) -> (c -> d -> Bool) -> Either a c -> Either b d -> Bool #

Ord2 Either 

Methods

liftCompare2 :: (a -> b -> Ordering) -> (c -> d -> Ordering) -> Either a c -> Either b d -> Ordering #

Read2 Either 

Methods

liftReadsPrec2 :: (Int -> ReadS a) -> ReadS [a] -> (Int -> ReadS b) -> ReadS [b] -> Int -> ReadS (Either a b) #

liftReadList2 :: (Int -> ReadS a) -> ReadS [a] -> (Int -> ReadS b) -> ReadS [b] -> ReadS [Either a b] #

Show2 Either 

Methods

liftShowsPrec2 :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> (Int -> b -> ShowS) -> ([b] -> ShowS) -> Int -> Either a b -> ShowS #

liftShowList2 :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> (Int -> b -> ShowS) -> ([b] -> ShowS) -> [Either a b] -> ShowS #

Braided (->) Either 

Methods

braid :: Either a b -> Either b a #

Symmetric (->) Either 
Monoidal (->) Either 

Associated Types

type Id ((->) :: * -> * -> *) (Either :: * -> * -> *) :: * #

Methods

idl :: Either (Id (->) Either) a -> a #

idr :: Either a (Id (->) Either) -> a #

coidl :: a -> Either (Id (->) Either) a #

coidr :: a -> Either a (Id (->) Either) #

Associative (->) Either 

Methods

associate :: Either (Either a b) c -> Either a (Either b c) #

disassociate :: Either a (Either b c) -> Either (Either a b) c #

PFunctor Either (->) (->) 

Methods

first :: (a -> b) -> Either a c -> Either b c #

QFunctor Either (->) (->) 

Methods

second :: (a -> b) -> Either c a -> Either c b #

Bifunctor Either (->) (->) (->) 

Methods

bimap :: (a -> b) -> (c -> d) -> Either a c -> Either b d #

(Tilable d a, Tilable d b) => Tilable d (Either a b) Source # 

Methods

duration :: Either a b -> d Source #

stretch :: d -> Either a b -> Either a b Source #

(Eq d, Num d, Lattice d) => PFunctor Either (FuncDelayP d iv) (FuncDelayP d iv) # 

Methods

first :: FuncDelayP d iv a b -> FuncDelayP d iv (Either a c) (Either b c) #

(Eq d, Num d, Lattice d) => PFunctor Either (FuncDurP d iv) (FuncDurP d iv) # 

Methods

first :: FuncDurP d iv a b -> FuncDurP d iv (Either a c) (Either b c) #

(Eq d, Num d, Lattice d) => QFunctor Either (FuncDelayP d iv) (FuncDelayP d iv) # 

Methods

second :: FuncDelayP d iv a b -> FuncDelayP d iv (Either c a) (Either c b) #

(Eq d, Num d, Lattice d) => QFunctor Either (FuncDurP d iv) (FuncDurP d iv) # 

Methods

second :: FuncDurP d iv a b -> FuncDurP d iv (Either c a) (Either c b) #

(Eq d, Num d, Lattice d) => Bifunctor Either (FuncDelayP d iv) (FuncDelayP d iv) (FuncDelayP d iv) # 

Methods

bimap :: FuncDelayP d iv a b -> FuncDelayP d iv c d -> FuncDelayP d iv (Either a c) (Either b d) #

(Eq d, Num d, Lattice d) => Bifunctor Either (FuncDurP d iv) (FuncDurP d iv) (FuncDurP d iv) # 

Methods

bimap :: FuncDurP d iv a b -> FuncDurP d iv c d -> FuncDurP d iv (Either a c) (Either b d) #

Monad (Either e) 

Methods

(>>=) :: Either e a -> (a -> Either e b) -> Either e b #

(>>) :: Either e a -> Either e b -> Either e b #

return :: a -> Either e a #

fail :: String -> Either e a #

Functor (Either a) 

Methods

fmap :: (a -> b) -> Either a a -> Either a b #

(<$) :: a -> Either a b -> Either a a #

MonadFix (Either e) 

Methods

mfix :: (a -> Either e a) -> Either e a #

Applicative (Either e) 

Methods

pure :: a -> Either e a #

(<*>) :: Either e (a -> b) -> Either e a -> Either e b #

(*>) :: Either e a -> Either e b -> Either e b #

(<*) :: Either e a -> Either e b -> Either e a #

Foldable (Either a) 

Methods

fold :: Monoid m => Either a m -> m #

foldMap :: Monoid m => (a -> m) -> Either a a -> m #

foldr :: (a -> b -> b) -> b -> Either a a -> b #

foldr' :: (a -> b -> b) -> b -> Either a a -> b #

foldl :: (b -> a -> b) -> b -> Either a a -> b #

foldl' :: (b -> a -> b) -> b -> Either a a -> b #

foldr1 :: (a -> a -> a) -> Either a a -> a #

foldl1 :: (a -> a -> a) -> Either a a -> a #

toList :: Either a a -> [a] #

null :: Either a a -> Bool #

length :: Either a a -> Int #

elem :: Eq a => a -> Either a a -> Bool #

maximum :: Ord a => Either a a -> a #

minimum :: Ord a => Either a a -> a #

sum :: Num a => Either a a -> a #

product :: Num a => Either a a -> a #

Traversable (Either a) 

Methods

traverse :: Applicative f => (a -> f b) -> Either a a -> f (Either a b) #

sequenceA :: Applicative f => Either a (f a) -> f (Either a a) #

mapM :: Monad m => (a -> m b) -> Either a a -> m (Either a b) #

sequence :: Monad m => Either a (m a) -> m (Either a a) #

Generic1 (Either a) 

Associated Types

type Rep1 (Either a :: * -> *) :: * -> * #

Methods

from1 :: Either a a -> Rep1 (Either a) a #

to1 :: Rep1 (Either a) a -> Either a a #

Eq a => Eq1 (Either a) 

Methods

liftEq :: (a -> b -> Bool) -> Either a a -> Either a b -> Bool #

Ord a => Ord1 (Either a) 

Methods

liftCompare :: (a -> b -> Ordering) -> Either a a -> Either a b -> Ordering #

Read a => Read1 (Either a) 

Methods

liftReadsPrec :: (Int -> ReadS a) -> ReadS [a] -> Int -> ReadS (Either a a) #

liftReadList :: (Int -> ReadS a) -> ReadS [a] -> ReadS [Either a a] #

Show a => Show1 (Either a) 

Methods

liftShowsPrec :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> Either a a -> ShowS #

liftShowList :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> [Either a a] -> ShowS #

(Lattice a, Lattice b) => Lattice (Complete (Either a b)) Source #

Derived lattice for Either

(Eq a, Eq b) => Eq (Either a b) 

Methods

(==) :: Either a b -> Either a b -> Bool #

(/=) :: Either a b -> Either a b -> Bool #

(Ord a, Ord b) => Ord (Either a b) 

Methods

compare :: Either a b -> Either a b -> Ordering #

(<) :: Either a b -> Either a b -> Bool #

(<=) :: Either a b -> Either a b -> Bool #

(>) :: Either a b -> Either a b -> Bool #

(>=) :: Either a b -> Either a b -> Bool #

max :: Either a b -> Either a b -> Either a b #

min :: Either a b -> Either a b -> Either a b #

(Read a, Read b) => Read (Either a b) 
(Show a, Show b) => Show (Either a b) 

Methods

showsPrec :: Int -> Either a b -> ShowS #

show :: Either a b -> String #

showList :: [Either a b] -> ShowS #

Generic (Either a b) 

Associated Types

type Rep (Either a b) :: * -> * #

Methods

from :: Either a b -> Rep (Either a b) x #

to :: Rep (Either a b) x -> Either a b #

Semigroup (Either a b) 

Methods

(<>) :: Either a b -> Either a b -> Either a b #

sconcat :: NonEmpty (Either a b) -> Either a b #

stimes :: Integral b => b -> Either a b -> Either a b #

(Lift a, Lift b) => Lift (Either a b) 

Methods

lift :: Either a b -> Q Exp #

(POrd a, POrd b) => POrd (Either a b) Source #

Derived partial order for Either

Methods

partialCompare :: Either a b -> Either a b -> Maybe Ordering Source #

pLeq :: Either a b -> Either a b -> Bool Source #

pOrdEq :: Either a b -> Either a b -> Bool Source #

pOrdMin :: [Either a b] -> Maybe (Either a b) Source #

pOrdMax :: [Either a b] -> Maybe (Either a b) Source #

pOrdReduceMin :: [Either a b] -> [Either a b] Source #

pOrdReduceMax :: [Either a b] -> [Either a b] Source #

(Eq d, Num d, Lattice d) => Braided (FuncDelayP d iv) Either # 

Methods

braid :: FuncDelayP d iv (Either a b) (Either b a) #

(Eq d, Num d, Lattice d) => Braided (FuncDurP d iv) Either # 

Methods

braid :: FuncDurP d iv (Either a b) (Either b a) #

(Eq d, Num d, Lattice d) => Symmetric (FuncDelayP d iv) Either # 
(Eq d, Num d, Lattice d) => Symmetric (FuncDurP d iv) Either # 
(Eq d, Num d, Lattice d) => Monoidal (FuncDelayP d iv) Either # 

Associated Types

type Id (FuncDelayP d iv :: * -> * -> *) (Either :: * -> * -> *) :: * #

Methods

idl :: FuncDelayP d iv (Either (Id (FuncDelayP d iv) Either) a) a #

idr :: FuncDelayP d iv (Either a (Id (FuncDelayP d iv) Either)) a #

coidl :: FuncDelayP d iv a (Either (Id (FuncDelayP d iv) Either) a) #

coidr :: FuncDelayP d iv a (Either a (Id (FuncDelayP d iv) Either)) #

(Eq d, Num d, Lattice d) => Monoidal (FuncDurP d iv) Either # 

Associated Types

type Id (FuncDurP d iv :: * -> * -> *) (Either :: * -> * -> *) :: * #

Methods

idl :: FuncDurP d iv (Either (Id (FuncDurP d iv) Either) a) a #

idr :: FuncDurP d iv (Either a (Id (FuncDurP d iv) Either)) a #

coidl :: FuncDurP d iv a (Either (Id (FuncDurP d iv) Either) a) #

coidr :: FuncDurP d iv a (Either a (Id (FuncDurP d iv) Either)) #

(Eq d, Num d, Lattice d) => Associative (FuncDelayP d iv) Either # 

Methods

associate :: FuncDelayP d iv (Either (Either a b) c) (Either a (Either b c)) #

disassociate :: FuncDelayP d iv (Either a (Either b c)) (Either (Either a b) c) #

(Eq d, Num d, Lattice d) => Associative (FuncDurP d iv) Either # 

Methods

associate :: FuncDurP d iv (Either (Either a b) c) (Either a (Either b c)) #

disassociate :: FuncDurP d iv (Either a (Either b c)) (Either (Either a b) c) #

(Updatable p1 d iv, Updatable p2 d iv) => Updatable (Either p1 p2) d iv Source #

Closure under binary disjoint sum

Methods

update :: UpdateData d iv -> Either p1 p2 -> Either p1 p2 Source #

type Id (->) Either 
type Id (->) Either = Void
type Rep1 (Either a) 
type Rep (Either a b) 
type Id (FuncDelayP d iv) Either # 
type Id (FuncDelayP d iv) Either = Void
type Id (FuncDurP d iv) Either # 
type Id (FuncDurP d iv) Either = Void
type (==) (Either k k1) a b 
type (==) (Either k k1) a b = EqEither k k1 a b

multiplex3 :: (Maybe [Event a], Maybe [Event b], Maybe [Event c]) -> Maybe [Event (Either a (Either b c))] Source #