Last active
August 29, 2015 14:05
-
-
Save Warry/1472519278124015ac7d to your computer and use it in GitHub Desktop.
this compiles !???
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface Functor<A>{ | |
flatMap<A,B> (f: (A) => B): Functor<B> | |
} | |
interface Monad<A> extends Functor<A> { | |
bind: (A) => Monad<A> | |
} | |
interface Option<A> extends Monad<A>{ | |
} | |
class Some<A> implements Option<A> { | |
private value: A | |
constructor(a: A) { | |
this.value = a | |
} | |
flatMap<A,B> (f: (A) => B): Some<B>{ | |
return new Some(f(this.value)) | |
} | |
bind (f: (A) => Some<A>): Some<A>{ | |
return f(this.value) | |
} | |
} | |
class None<A> implements Option<A>{ | |
flatMap<A,B> (f: (A) => B): None<B> { | |
return new None<B>() | |
} | |
bind (f: (A) => None<A>): None<A>{ | |
return this | |
} | |
} | |
var test:Option<string> = new Some(4) | |
test = new None() | |
test = new Some(false) // ! \o/ this compiles... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment