Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
this compiles !???
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
You can’t perform that action at this time.