instances
- class List(*xs, **ys)
Class Methods
new :
... -> Typefmap :
(A -> B) -> List A -> List Bunit :
A -> List Alift2 :
(A -> B -> C) -> List A -> List B -> List Cjoin :
List List A -> List Abind :
List A -> (A -> List B) -> List B
- class Object(xs)
- classmethod fmap(f)
Map a function on lists.
- classmethod join(xx)
Flatten a list of lists.
- Parameters:
xx (cls(cls('A')))
- Return type:
cls(‘A’)
- src
alias of
Type
- tgt
alias of
Type
- classmethod unit(a)
Singleton list.
- class Bool(x)
Boolean values.
- show()
Print x, prefixed by its name if any, and return x.
- Parameters:
x (Any)
- Return type:
Any
- shows(m)
Print a value x and set its name, returning x.
- Parameters:
x (Any)
m (str)
- Return type:
Any
- class Float(x=0, /)
- show()
Print x, prefixed by its name if any, and return x.
- Parameters:
x (Any)
- Return type:
Any
- shows(m)
Print a value x and set its name, returning x.
- Parameters:
x (Any)
m (str)
- Return type:
Any
- class Int
- show()
Print x, prefixed by its name if any, and return x.
- Parameters:
x (Any)
- Return type:
Any
- shows(m)
Print a value x and set its name, returning x.
- Parameters:
x (Any)
m (str)
- Return type:
Any
- class Wrap(*xs, **ys)
Type wrapper lifting selected methods to the container type.
Class Methods
new :
... -> Typefmap :
(A -> B) -> Wrap A -> Wrap B
The class method
liftwill iterate over the class attribute_lifted_methods_to assign lifted methods on the wrapped type.Attributes:
- _lifted_methods_ (
list): - A list of of triples
(name, signature, lift_args)where name (
str): name of the method to be lifted,signature (
Callable[type, Type]) yielding lifted method typesignature(cls),lift_args (
int | tuple[int] | type(...)) index of arguments to be unwrapped.
Example
class StrWrapper(Wrap): _lifted_methods_ = [ ('upper', lambda A: Hom(A, A), ...) ('isalnum', lambda A: Hom(A, Bool), ...) ('join', lambda A: Hom((A, List[A]), Bool), 0) ]
- A list of of triples
- Object
alias of
WrapObject
- classmethod lift(method, homtype, lift_args=Ellipsis)
Lift a method to the wrapped type.
- Parameters:
method (MethodType)
homtype (Type)
lift_args (Iterable[int] | ellipsis)
- Return type:
HomObject
- class WrapObject(data)
Base type for wrapped values.
- show()
Print x, prefixed by its name if any, and return x.
- Parameters:
x (Any)
- Return type:
Any
- shows(m)
Print a value x and set its name, returning x.
- Parameters:
x (Any)
m (str)
- Return type:
Any
- class State(*xs, **ys)
State bifunctor and monad.
Class Methods
new :
... -> Typefmap :
(A -> B) -> (State X A) -> State X Bcofmap :
(X -> Y) -> (State Y A) -> State X Acompose :
(State A B) -> (State B C) -> State A Ceval :
A -> (State A B) -> B
The type
State(S, A)describes stateful computations yielding a return value of typeAwhile acting on the state typeS. The isomorphism:S -> (S, A) ~= State(S, A)
may be used as a decorator do define stateful computations.:
>>> @State(Str, Str) ... def popchar(s): ... return s[1:], s[0] ... >>> popchar.run("cat") (Str, Str) : ('at', 'c')
Calling
Statewith only one argumentSwill return aStateMonadsubclass with a class attribute_state_. Calling this monad on a typeAwill also return the typeState(S, A), i.e.:>>> isinstance(State(Str), Monad) True >>> State(Str, Int) is State(Str)(Int) True # monadic types `State S A` are of type `State` >>> type(State(Str)(Int) is State) True
Note that this is an important difference with the
Statefulimplementation, which puts the emphasis on state-type specific implementations. Using theStatebifunctor may be considered safer at a little convenience cost (the global class state ofStateful(S, s0)types).- class Object(*args, **kwargs)
Stateful computation.
- bind(mf)
- exec(s=None)
- gets(f, tgt=None)
- map(f)
Bound
mapmethod, equivalent toFunctor.fmap(f)(x).
- put(s)
- puts(f)
- run(s=None)
- show()
Print x, prefixed by its name if any, and return x.
- Parameters:
x (Any)
- Return type:
Any
- shows(m)
Print a value x and set its name, returning x.
- Parameters:
x (Any)
m (str)
- Return type:
Any
- then(f, tgt=None)
- unit(a)
- use(state)
- classmethod eval(s, f)
Evaluate
fon inputx.
- classmethod fmap(f)
Pushforward : post-composition on the target.
- classmethod gets(f)
- classmethod new(S, A=Ellipsis)
- classmethod put(s)
- classmethod puts(f)
- class StateMonad(*xs, **ys)
State monad.
Class Methods
new :
... -> Typefmap :
(A -> B) -> (StateMonad A) -> StateMonad Bunit :
A -> StateMonad Alift2 :
(A -> B -> C) -> (StateMonad A) -> (StateMonad B) -> StateMonad Cjoin :
(StateMonad StateMonad A) -> StateMonad Abind :
(StateMonad A) -> (A -> StateMonad B) -> StateMonad B
The monad
State Smaps any typeAto the stateful computation typeState S A.- classmethod chain(*sts)
- classmethod fmap(f)
Map pure callables
A -> Bby post-transform of the return value.>>> State.fmap(f)(st_a)(s0) == st_a.exec(s0), f(st_a.eval(s0)) True
- classmethod gets(f)
Get and return an image of the state by
f : S -> A.
- classmethod join(ffa)
Evaluate the returned stateful subprocess.
- classmethod new(A)
- classmethod put(s)
Update the state and return
().
- classmethod puts(f)
Update the state by an image of
f : A -> S.
- src
alias of
Type
- tgt
alias of
Type
- classmethod unit(a=())
Return a value
a : A.
- class Stateful(S, initial=None, dct=None)
- class StatefulMonad(*xs, **ys)
Stateful Monads on a pointed state type.
Fully stateful monads are defined by both a state type
Sand an initial state_initial_ : S.>>> MyString = Stateful(Str, "Hello World!")
- class Object(*args, **kwargs)
- arity: int = 1
- run(s=None)
- show()
Print x, prefixed by its name if any, and return x.
- Parameters:
x (Any)
- Return type:
Any
- shows(m)
Print a value x and set its name, returning x.
- Parameters:
x (Any)
m (str)
- Return type:
Any
- property state
- property value
- classmethod new(A)
- classmethod use(s0)
Context manager for the
_initial_class attribute.Within a managed block, evaluation of any stateful instance will be computed from
s0.- Yields:
put_s0 (cls(Type.Unit)) – a stateful instance with initial state
s0and returning().- Parameters:
s0 (S)