Created
May 4, 2014 09:00
-
-
Save oakwhiz/7ae602aa069ef421371f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
template <class <typename> F> | |
struct Functor : private Applicative<F> { | |
template <typename T, typename Function> | |
static F<T> fmap(Function&& f, F<T> x) { | |
return ap(pure(move(f)), move(x)); | |
} | |
}; | |
template <class <typename> M> | |
struct Applicative<M> : private Monad<M> { | |
template <typename T> | |
static M<T> pure(T&& x) { | |
return ret(forward<T>(x)); | |
} | |
template <typename Function, typename T> | |
static M<T> ap(M<Function> mf, M<T> mx) { | |
return bind(move(x), [&mx](Function f) { | |
return bind( | |
move(mx), | |
[&f](T x) { | |
return ret(f(move(x))); | |
} | |
); | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment