<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-8429813273258857820</id><updated>2011-08-02T18:24:46.411-04:00</updated><title type='text'>Sean McEligot</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://seanmceligot.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8429813273258857820/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://seanmceligot.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Sean McEligot</name><uri>http://www.blogger.com/profile/15815160869147788296</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>1</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-8429813273258857820.post-8168907760531067761</id><published>2010-08-14T23:12:00.005-04:00</published><updated>2010-08-15T11:56:34.570-04:00</updated><title type='text'>Monads in Upcoming Java 7</title><content type='html'>&lt;span style="font-style:italic;"&gt;Under Construction&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;script type="syntaxhighlighter" class="brush: java"&gt;&lt;![CDATA[

public class Monad&lt;T&gt; {
  public final T t;
  public Monad(T t) {
    this.t = t;
  }
  public String toString() {
    return "Monad("+t+")";
  }
 public abstract static class Fun1&lt;a,b&gt; {
  public abstract b apply(a a);
 }
 public abstract static class Fun2&lt;a,b,c&gt; {
  public Fun1 curry(final a a) {
   final Fun2 fun2 = this;
      return #(b) { return fun2.apply(a,b);};
  }
  public abstract c apply(a a, b b);
 }
  
  public static &lt;T&gt; Monad&lt;T&gt; mreturn(final T t) {
    return new Monad(t); 
  } 
  // (m t)-&gt;(t-&gt;m u)-&gt;(m u)
  public static &lt;T,U&gt; Monad&lt;U&gt; mbind(final Monad&lt;T&gt; mt, Fun1&lt;T,Monad&lt;U&gt;&gt; tmu) {
    return tmu.apply(mt.t);
  }
  public static Monad mdo(Monad m, Fun1... ff) {
    Monad n = m;
    for(Fun1 f: ff) {
      n = mbind(n, f);
    }
    return n;
  }
  public static void main(String[] args) {
    Monad.Fun1&lt;Integer,Monad&lt;Integer&gt;&gt; minc = #(x){ return new Monad(new Integer(x+1));};

    Monad.Fun2&lt;Integer,Integer,Monad&lt;Float&gt;&gt; mdiv = #(a,b){ return new Monad(new Float(a.floatValue()/b));};
    Monad m = new Monad(1); 
    Monad&lt;Float&gt; o = Monad.mdo(
        m, // 1
        minc, // 2
        minc, // 3
        minc, // 4
        mdiv.curry(2) // 0.5
        );
    System.out.println(o); // 0.5
  }
}
    
    

]]&gt;&lt;/script&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8429813273258857820-8168907760531067761?l=seanmceligot.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://seanmceligot.blogspot.com/feeds/8168907760531067761/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://seanmceligot.blogspot.com/2010/08/monads-in-upcoming-java-7.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8429813273258857820/posts/default/8168907760531067761'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8429813273258857820/posts/default/8168907760531067761'/><link rel='alternate' type='text/html' href='http://seanmceligot.blogspot.com/2010/08/monads-in-upcoming-java-7.html' title='Monads in Upcoming Java 7'/><author><name>Sean McEligot</name><uri>http://www.blogger.com/profile/15815160869147788296</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>
