junkcode  Check-in [ae91a65ab8]

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

Overview
Comment:Change signature of disposable-wrapping bit.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256:ae91a65ab8b383b28db0bed68e8c29a81c5a53c51911593896bd3de515438ed2
User & Date: jaccarmac 2018-01-29 06:31:41
Context
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
06:28
Add additional behavior. check-in: 3fc59ce7ea user: jaccarmac tags: trunk
Changes

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

14
15
16
17
18
19
20
21
22
23
24
                new ResourcePrinterFree<Unit>.Return(unit));
            freeProgram.Map(FreeInterpreter.Interpret);

            TypeclassProgram<ResourcePrinterTypeclassAllCapsImpl>();
        }

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







<
|


14
15
16
17
18
19
20

21
22
23
                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!"));
    }
}

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

1
2

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


using static LanguageExt.Prelude;

namespace free_monad_vs_typeclass {
    public interface ResourcePrinterTypeclass {
        Unit Print(ResourceWrapper resource, string output);
        ResourceWrapper AcquireResource();
    }

    public struct ResourcePrinterTypeclassImpl : ResourcePrinterTypeclass {
        public Unit Print(ResourceWrapper resource, string output) =>
            fun(() => resource.Print(output))();
        
        public ResourceWrapper AcquireResource() =>
            new ResourceWrapper();
    }

    public struct ResourcePrinterTypeclassAllCapsImpl : ResourcePrinterTypeclass {
        public Unit Print(ResourceWrapper resource, string output) =>
            fun(() => resource.Print(output.ToUpper()))();
        
        public ResourceWrapper AcquireResource() =>
            new ResourceWrapper();
    }
}


>






|






|
|






|
|


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

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);
    }

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