本間 雅洋 (Masahiro Honma) > Data-Monad-0.04 > Data::Monad::Base::Monad

Download:
Data-Monad-0.04.tar.gz

Dependencies

Annotate this POD

Website

View/Report Bugs
Source   Latest Release: Data-Monad-0.07

NAME ^

Data::Monad::Base::Monad - The base class of any monads.

SYNOPSIS ^

  package YourMonadClass;
  use base qw/Data::Monad::Base::Monad/;

  sub unit {
      my ($class, @v) = @_;
      ...
  }

  sub flat_map {
      my ($self, $f) = @_;
      ...
  }

DESCRIPTION ^

Data::Monad::Base::Monad provides some useful functions for any monads.

You must implement unit() and flat_map() according to monad laws. Or you may implement flatten() and map() instead of flat_map().

This module is marked EXPERIMENTAL. API could be changed without any notice. I'll drop many useless stuffs in the future.

METHODS ^

$m = SomeMonad->unit(@vs);

A natural transformation, which is known as "return" in Haskell.

You must implement this method in sub classes.

$f = SomeMonad->flat_map_multi(sub { ... }, $m1, $m2, ...);

Changes the type of function from (v1, v2, ...) -> m(v0) to (m(v1), m(v2), ...) -> m(v0), and apply it to $m1, $m2, ...

$f = SomeMonad->map_multi(sub { ... }, $m1, $m2, ...);

Changes the type of function from (v1, v2, ...) -> v0 to (m(v1), m(v2), ...) -> m(v0), and apply it to $m1, $m2, ...

$m = SomeMonad->sequence($m1, $m2, $m3, ...);

Packs monads into the new monad.

$m2 = $m1->flat_map(sub { ... });

The composition of Kleisli category, which known as ">>=" in Haskell.

You must implement this method in sub classes.

$m2 = $m1->map(sub { ... });

The morphism map of the monad, which is known as "fmap" in Haskell.

$m = $mm->flatten;

A natural transformation, which is known as "join" in Haskell.

$m = $mf->ap($m1, $m2,...);

Executes the function which wrapped by the monad.

$m = $m->while(\&predicate, \&f);

flat_map(\&f) while \&predicate is true.

AUTHOR ^

hiratara <hiratara {at} cpan.org>

SEE ALSO ^

Data::Monad::Base::MonadZero, Data::Monad::Base::Sugar

LICENSE ^

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

syntax highlighting: