Experiment with this gist in Gistlyn.
Let's start with the big guns: Discriminated Union in C#.
| /* | |
| https://dba.stackexchange.com/questions/96534/postgres-check-disk-space-taken-by-materialized-view?newreg=6b1d58604fce4a1fbe3033ddbb52d7ca | |
| relkind: | |
| r = ordinary table, | |
| i = index, | |
| S = sequence, | |
| v = view, | |
| m = materialized view, | |
| c = composite type, |
Experiment with this gist in Gistlyn.
Let's start with the big guns: Discriminated Union in C#.
| using System; | |
| public class Test | |
| { | |
| public static void Main() | |
| { | |
| var x = ImZipper<int>.Empty.Pre(1).Pre(2); | |
| Console.WriteLine(x); | |
| Console.WriteLine(x.Focus); | |
| } |
| using System; | |
| using System.Collections.Generic; | |
| using static System.Console; | |
| namespace Union | |
| { | |
| class Program | |
| { | |
| public static void Main() | |
| { |
| /* | |
| Inspired by: https://medium.com/@gcanti/introduction-to-optics-lenses-and-prisms-3230e73bfcfe | |
| */ | |
| using System; | |
| using static System.Console; | |
| public static class Program | |
| { | |
| public static void Main() |
| /* | |
| StackPool is faster by far >10 times than ScanPool. | |
| Other features: | |
| - Does not consume memory from the start - it grows only when you Return object to it. | |
| - Forgiving for no Return scenarios, that means when you not returning - memory is not consumed. So it is similar to `new` | |
| - May be put a limit on depth, NOT tested yet. | |
| */ |
| using System; | |
| using System.Threading; | |
| using static System.Console; | |
| public class Test | |
| { | |
| public static void Main() | |
| { | |
| var p = new StackPool<S>(); | |
| var s1 = Rent(p, "55"); |
| <!-- Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. --> | |
| <Project> | |
| <PropertyGroup> | |
| <!-- Respect environment variable for the NuGet Packages Root if set; otherwise, use the current default location --> | |
| <NuGetPackageRoot Condition="'$(NuGetPackageRoot)' == ''">$(NUGET_PACKAGES)</NuGetPackageRoot> | |
| <NuGetPackageRoot Condition="'$(NuGetPackageRoot)' == '' AND '$(OS)' == 'Windows_NT'">$(UserProfile)\.nuget\packages\</NuGetPackageRoot> | |
| <NuGetPackageRoot Condition="'$(NuGetPackageRoot)' == '' AND '$(OS)' != 'Windows_NT'">$([System.Environment]::GetFolderPath(SpecialFolder.Personal))\.nuget\packages\</NuGetPackageRoot> | |
| <NuGetPackageRoot Condition="!HasTrailingSlash('$(NuGetPackageRoot)')">$(NuGetPackageRoot)\</NuGetPackageRoot> | |
| </PropertyGroup> | |
| </Project> |
| using System; | |
| public class C { | |
| public Result<int>.Or M() => | |
| Result<int>.Left(2); | |
| } | |
| public class Result<T> : Either<T, Exception> {} | |
| public class Either<L, R> | |
| { |
| /* | |
| Modified from the original https://gist.github.com/louthy/524fbe8965d3a2aae1b576cdd8e971e4 | |
| - removed dependency on [language-ext](https://github.com/louthy/language-ext) | |
| - separated monadic boilerplate, so you may concentrate on describing the operations and interpretation of the program | |
| - removed `IO<A>.Faulted` to simplify the examples. It can be added back in straightforward manner. | |
| Useful links: | |
| - [John DeGoes: Beyond Free Monads - λC Winter Retreat 2017](https://www.youtube.com/watch?v=A-lmrvsUi2Y) | |
| - [Free and tagless compared - how not to commit to a monad too early](https://softwaremill.com/free-tagless-compared-how-not-to-commit-to-monad-too-early) |