Monads are types that implement two functions with a fixed signature: unit and bind.
In the Haskell notation:
unit :: a -> m a
bind :: m a -> (a -> m b) -> m b
unittransfers an object from type ato mtype a. The type amust be arbitrary. Implementation bindcan be anything (but it must satisfy monadic laws).
Try converting your example to Haskell syntax:
People are just a tuple:
type People = (String, String)
A friend type is a triplex of two Boolean elements and a string.
If we use these types, then your Friends.unit method looks something like this:
unit_friends :: People -> Friends
unit_friends _ = (false, false)
, unit_friends Friends. unit. :
unit_friends :: a -> Friends a
Java :
public static Friends<T> unit(T from) {
}
bind ToFromFunction People - Friends:
bind_friends :: ToFromFunction -> People -> Friends
ToFromFunction
type ToFromFunction = People -> Friends -> Friends
act.
bind_friends :: (People -> Friends -> Friends) -> People -> Friends
bind_friends, - :
bind_friends :: People -> (People -> Friends -> Friends) -> Friends
:
bind_friends :: Friends a -> (a -> Friends b) -> Friends b
, .
, . bind_friends Friends, People, bind ToFromFunction Friends.