forsyde-atom-0.3.0.0: Shallow-embedded DSL for modeling cyber-physical systems
Copyright(c) George Ungureanu KTH/ICT/ESY 2015-2020
LicenseBSD-style (see the file LICENSE)
Maintainerugeorge@kth.se
Stabilityexperimental
Portabilityportable
Safe HaskellSafe
LanguageHaskell2010
ExtensionsPostfixOperators

ForSyDe.Atom.Utility.Tuple

Description

This module implements general purpose utility functions. It mainly hosts functions dealing with tuples. Utility are provided for up until 9-tuples. Follow the examples in the source code in case it does not suffice.

IMPORTANT!!! Most of the multi-parameter higher-order functions provided by the library API are named along the lines of functionMN where M represents the number of curried inputs (i.e. a1 -> a2 -> ... -> aM), while N represents the number of tupled outputs (i.e. (b1,b2,...,bN)). To avoid repetition we document only functions with 2 inputs and 2 outputs (i.e. function22).

Synopsis
  • at22 :: (a1, a2) -> a2
  • (||<) :: (Functor f1, Functor f2) => f1 (f2 (a1, a2)) -> (f1 (f2 a1), f1 (f2 a2))
  • (><) :: (a1 -> a2 -> b1) -> (a1, a2) -> b1
  • ($$) :: (a1 -> b1, a2 -> b2) -> (a1, a2) -> (b1, b2)

Documentation

at22 :: (a1, a2) -> a2 Source #

The atxy functions return the y-th element of an x-tuple.

ForSyDe.Atom.Utility exports the constructors below. Please follow the examples in the source code if they do not suffice:

at21, at22,
at31, at32, at33,
at41, at42, at43, at44,
at51, at52, at53, at54, at55,
at61, at62, at63, at64, at65, at66, 
at71, at72, at73, at74, at75, at76, at77,
at81, at82, at83, at84, at85, at86, at87, at88,
at91, at92, at93, at94, at95, at96, at97, at98, at99,

Example:

>>> at53 (1,2,3,4,5)
3

(||<) :: (Functor f1, Functor f2) => f1 (f2 (a1, a2)) -> (f1 (f2 a1), f1 (f2 a2)) infixl 3 Source #

This set of utility functions "unzip" nested n-tuples, provided as postfix operators. They are crucial for reconstructing data types from higher-order functions which input functions with multiple outputs. It relies on the nested types being instances of Functor.

The operator convention is (|+<+), where the number of | represent the number of layers the n-tuple is lifted, while the number of < + 1 is the order n of the n-tuple.

ForSyDe.Atom.Utility exports the constructors below. Please follow the examples in the source code if they do not suffice:

   |<,    |<<,    |<<<,    |<<<<,    |<<<<<,    |<<<<<<,    |<<<<<<<,    |<<<<<<<<,
  ||<,   ||<<,   ||<<<,   ||<<<<,   ||<<<<<,   ||<<<<<<,   ||<<<<<<<,   ||<<<<<<<<,
 |||<,  |||<<,  |||<<<,  |||<<<<,  |||<<<<<,  |||<<<<<<,  |||<<<<<<<,  |||<<<<<<<<,  
||||<, ||||<<, ||||<<<, ||||<<<<, ||||<<<<<, ||||<<<<<<, ||||<<<<<<<, ||||<<<<<<<<, 

Example:

>>> :set -XPostfixOperators
>>> ([Just (1,2,3), Nothing, Just (4,5,6)] ||<<)
([Just 1,Nothing,Just 4],[Just 2,Nothing,Just 5],[Just 3,Nothing,Just 6])

(><) :: (a1 -> a2 -> b1) -> (a1, a2) -> b1 infixl 6 Source #

Infix currying operators used for convenience.

The operator convention is (><+), where the number of < + 1 is the order n of the n-tuple.

ForSyDe.Atom.Utility exports the constructors below. Please follow the examples in the source code if they do not suffice:

><, ><<, ><<<, ><<<<, ><<<<<, ><<<<<<, ><<<<<<<, ><<<<<<<<

Example:

>>> (+) >< (1,2)
3

($$) :: (a1 -> b1, a2 -> b2) -> (a1, a2) -> (b1, b2) infixl 6 Source #

Infix function application operator for tuples.

The operator convention is ($+), where the number of $ is the order n of the n-tuple. For Applying a function on nontuples we rely on $ provided by Prelude.

ForSyDe.Atom.Utility exports the constructors below. Please follow the examples in the source code if they do not suffice:

$$, $$$, $$$$, $$$$$, $$$$$$, $$$$$$$, $$$$$$$$, $$$$$$$$$

Example:

>>> ((+),(-)) $$ (1,1) $$ (2,2)
(3,-1)