namespace Monads.ContinuationMonad
public static void Main()
Func<int, int> square = x => x * x;
from func in square.ToContinuation<Func<int, int>, int>()
from y in 3.ToContinuation<int, int>()
Console.WriteLine(result);
public delegate T Cont<U, T>(Func<U, T> f);
public static class Extensions
public static Cont<U, T> ToContinuation<U, T>(this U x)
return (callback) => callback(x);
public static Cont<V, Answer> SelectMany<T, U, V, Answer>(this Cont<T, Answer> m, Func<T, Cont<U, Answer>> k, Func<T, U, V> selector)
return (Func<V, Answer> c) => m(t => k(t)(y => c(selector(t, y))));