Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Nomads explained

Name: Anonymous 2011-04-05 17:49

x >>= f >>= g >>= h
is
h(do_monad_magic(g(do_monad_magic(f(do_monad_magic(x))))))

Name: Anonymous 2011-04-05 18:51

>>2

function call($x, $f) { return $f($x); }
function identity($x) { return $x; }
class Monad {
   protected $bind_;
   protected $unit_;
   public function __construct($bind = 'call', $unit = 'identity') {
         $this->bind_ = $bind;
      $this->unit_ = $unit;
   }
   public function unit($x) { return call_user_func($this->unit_, $x); }
   public function bind($x, $f) { return call_user_func_array($this->bind_, array($x, $f)); }
}

$IdentityMonad = new Monad();

function lm_unit($x) { return array(0 => $x); }
function lm_append($x, $f) {
     return array_merge(array_map($f, $x));
}


$ListMonad = new Monad('lm_append', 'lm_unit');

function add1($x) { return $x+1; }
print_r($ListMonad->bind($ListMonad->unit(2), 'add1'));

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List