junkcode  Check-in [fc47a431e3]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Add static using to simplify things.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256:fc47a431e34df80d400eec451cf65b7042098260365011edea45d8a024547e54
User & Date: jaccarmac 2018-01-29 06:46:26
Context
2018-03-22
01:55
Upcoming Stern-Brocot tree project. check-in: d7c5628486 user: jaccarmac tags: trunk
2018-01-29
06:46
Add static using to simplify things. check-in: fc47a431e3 user: jaccarmac tags: trunk
06:31
Change signature of disposable-wrapping bit. check-in: ae91a65ab8 user: jaccarmac tags: trunk
Changes

Changes to free-monad-vs-typeclass/Program.cs.

1
2
3
4

5
6
7
8
9
10
11
..
13
14
15
16
17
18
19
20
21
22
23
using LanguageExt;
using LanguageExt.ClassInstances;
using System;


using static LanguageExt.Prelude;

namespace free_monad_vs_typeclass
{
    public class Program
    {
        public static void Main(string[] args)
................................................................................
            var freeProgram = new ResourcePrinterFree<Unit>.Print("Hello, world!", () =>
                new ResourcePrinterFree<Unit>.Return(unit));
            freeProgram.Map(FreeInterpreter.Interpret);

            TypeclassProgram<ResourcePrinterTypeclassAllCapsImpl>();
        }

        public static Unit TypeclassProgram<ResourcePrinterTypeclassT>() where ResourcePrinterTypeclassT: struct, ResourcePrinterTypeclass =>
            default(ResourcePrinterTypeclassT).AcquireResource(r => default(ResourcePrinterTypeclassT).Print(r, "Hello, world!"));
    }
}




>







 







|
|


1
2
3
4
5
6
7
8
9
10
11
12
..
14
15
16
17
18
19
20
21
22
23
24
using LanguageExt;
using LanguageExt.ClassInstances;
using System;

using static free_monad_vs_typeclass.ResourcePrinterTypeclassExtensions;
using static LanguageExt.Prelude;

namespace free_monad_vs_typeclass
{
    public class Program
    {
        public static void Main(string[] args)
................................................................................
            var freeProgram = new ResourcePrinterFree<Unit>.Print("Hello, world!", () =>
                new ResourcePrinterFree<Unit>.Return(unit));
            freeProgram.Map(FreeInterpreter.Interpret);

            TypeclassProgram<ResourcePrinterTypeclassAllCapsImpl>();
        }

        public static Unit TypeclassProgram<T>() where T: struct, ResourcePrinterTypeclass =>
            rpacquireResource<T, Unit>(r => rpprint<T>(r, "Hello, world!"));
    }
}

Changes to free-monad-vs-typeclass/ResourcePrinterTypeclass.cs.

5
6
7
8
9
10
11








12
13
14
15
16
17
18
using static LanguageExt.Prelude;

namespace free_monad_vs_typeclass {
    public interface ResourcePrinterTypeclass {
        Unit Print(ResourceWrapper resource, string output);
        T AcquireResource<T>(Func<ResourceWrapper, T> f);
    }









    public struct ResourcePrinterTypeclassImpl : ResourcePrinterTypeclass {
        public Unit Print(ResourceWrapper resource, string output) =>
            fun(() => resource.Print(output))();
        
        public T AcquireResource<T>(Func<ResourceWrapper, T> f) =>
            use(new ResourceWrapper(), f);







>
>
>
>
>
>
>
>







5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
using static LanguageExt.Prelude;

namespace free_monad_vs_typeclass {
    public interface ResourcePrinterTypeclass {
        Unit Print(ResourceWrapper resource, string output);
        T AcquireResource<T>(Func<ResourceWrapper, T> f);
    }

    public static class ResourcePrinterTypeclassExtensions {
        public static Unit rpprint<T>(ResourceWrapper resource, string output) where T: struct, ResourcePrinterTypeclass =>
            default(T).Print(resource, output);
        
        public static U rpacquireResource<T, U>(Func<ResourceWrapper, U> f) where T: struct, ResourcePrinterTypeclass =>
            default(T).AcquireResource(f);
    }

    public struct ResourcePrinterTypeclassImpl : ResourcePrinterTypeclass {
        public Unit Print(ResourceWrapper resource, string output) =>
            fun(() => resource.Print(output))();
        
        public T AcquireResource<T>(Func<ResourceWrapper, T> f) =>
            use(new ResourceWrapper(), f);