Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Cont monad in C#
// Cont monad in C#. //Rextester.Program.Main is the entry point for your code. Don't change it. using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester { public delegate TR Cont<TA, TR>(Func<TA, TR> c); public static class LinqContMonad { public static Cont<TU, TR> Select<TA, TR, TU>(this Cont<TA, TR> p, Func<TA, TU> selector) { return c => p(a => c(selector(a))); } public static Cont<TV, TR> SelectMany<TA, TR, TU, TV>( this Cont<TA, TR> p, Func<TA, Cont<TU, TR>> selector, Func<TA, TU, TV> projector) { return c => p(a => selector(a)(u => c(projector(a, u)))); } } public class Program { public static void Main(string[] args) { Cont<int, string> ex1 = from a in (Cont<int, string>)(c => c(1)) from b in (Cont<int, string>)(c => c(10)) select a + b; // result1 == "11" string result1 = ex1(x => x.ToString()); Console.WriteLine(result1); Cont<int, string> ex2 = from a in (Cont<int, string>)(c => c(1)) from b in (Cont<int, string>)(fred => "escape") select a + b; // result2 == "escape" string result2 = ex2(x => x.ToString()); Console.WriteLine(result2); Cont<int, string> ex3 = from a in (Cont<int, string>)(c => c(1)) from b in (Cont<int, string>)(fred => fred(10) + fred(20) ) select a + b; // result3 == "1121" string result3 = ex3(x => x.ToString()); Console.WriteLine(result3); } } }
run
|
edit
|
history
|
help
0
1
Konakubo Wall
dynamic in C#
Captcha
R
Create HardwareConfigs
Event test
30272 Program Ex5_1 if else_2
services
t