Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
The Sc3 multiple channel expansion (Mce) rules over an abstract type.
Synopsis
- data Mce t
- = Mce_Scalar t
- | Mce_Vector [Mce t]
- mce_is_well_formed :: Mce t -> Bool
- mce_is_scalar :: Mce t -> Bool
- mce_from_list :: [t] -> Mce t
- mce_to_list :: Mce t -> [t]
- mce_show :: Show t => Mce t -> String
- mce_scalar_value :: Mce t -> t
- mce_length :: Mce a -> Int
- mce_depth :: Mce a -> Int
- mce_extend :: Int -> Mce t -> Mce t
- mce_map :: (a -> b) -> Mce a -> Mce b
- mce_binop :: (a -> b -> c) -> Mce a -> Mce b -> Mce c
Documentation
Multiple channel expansion. The Mce type is a tree, however in hsc3 Mce_Vector will always hold Mce_Scalar elements.
Mce_Scalar t | |
Mce_Vector [Mce t] |
Instances
Functor Mce Source # | |
Floating n => Floating (Mce n) Source # | |
Num n => Num (Mce n) Source # | |
Read t => Read (Mce t) Source # | |
Fractional n => Fractional (Mce n) Source # | |
Show t => Show (Mce t) Source # | |
Eq t => Eq (Mce t) Source # | |
Ord t => Ord (Mce t) Source # | |
mce_is_well_formed :: Mce t -> Bool Source #
There are two invariants: 1. Mce should not be empty, ie. Mce_Vector should not have a null list. 2. Scalar Mce values should not be written as one-place vectors.
>>>
mce_is_well_formed (Mce_Vector [])
False
>>>
mce_is_well_formed (Mce_Vector [Mce_Scalar 1])
False
mce_is_scalar :: Mce t -> Bool Source #
Is Mce scalar.
mce_from_list :: [t] -> Mce t Source #
fromList for Mce, generates well-formed Mce.
mce_to_list :: Mce t -> [t] Source #
toList for Mce.
>>>
let v = Mce_Vector
>>>
mce_to_list (v[v[1, 2], 3, v[4, 5]])
[1,2,3,4,5]
mce_show :: Show t => Mce t -> String Source #
Pretty printer for Mce.
>>>
let v = Mce_Vector
>>>
mce_show (v[1, 2, v[3, 4]] * 5 + v[6, 7, 8])
"[11, 17, [23, 28]]"
mce_scalar_value :: Mce t -> t Source #
Read value from Mce_Scalar, error if Mce is Mce_Vector
mce_length :: Mce a -> Int Source #
Length, or perhaps rather width, of Mce. Considers only the outermost level, i.e. mce_length is not necessarily the length of mce_to_list.
mce_depth :: Mce a -> Int Source #
The depth of an Mce is the longest sequence of nested Mce_Vector nodes.
>>>
mce_depth 1
1
>>>
mce_depth (Mce_Vector [1, 2])
1
>>>
let v = Mce_Vector
>>>
mce_depth (v[v[1, 2], 3, v[4, 5]])
2
>>>
mce_depth (v[v[1, 2, 3, v[4, 5], 6], 7])
3