junkcode
Check-in [d88da710cd]
Not logged in

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

Overview
Comment:Move back to a simpler way.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256:d88da710cd53b636de1ae0bb60040eb918321a935bfb978ca1194b8ff501e759
User & Date: jaccarmac 2018-01-29 06:27:06
Context
2018-01-29
06:28
Add additional behavior. check-in: 3fc59ce7ea user: jaccarmac tags: trunk
06:27
Move back to a simpler way. check-in: d88da710cd user: jaccarmac tags: trunk
05:57
Simplify further. check-in: 23c2fc6b5b user: jaccarmac tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

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

13
14
15
16
17
18
19
20
21
22
23
24
            var freeProgram = new ResourcePrinterFree<Unit>.Print("Hello, world!", () =>
                new ResourcePrinterFree<Unit>.Return(unit));
            freeProgram.Map(FreeInterpreter.Interpret);

            TypeclassProgram<ResourcePrinterTypeclassImpl>();
        }

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







|
|
|


13
14
15
16
17
18
19
20
21
22
23
24
            var freeProgram = new ResourcePrinterFree<Unit>.Print("Hello, world!", () =>
                new ResourcePrinterFree<Unit>.Return(unit));
            freeProgram.Map(FreeInterpreter.Interpret);

            TypeclassProgram<ResourcePrinterTypeclassImpl>();
        }

        public static Unit TypeclassProgram<ResourcePrinterTypeclassT>() where ResourcePrinterTypeclassT: struct, ResourcePrinterTypeclass =>
            use(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
using LanguageExt;
using LanguageExt.TypeClasses;

using static LanguageExt.Prelude;

namespace free_monad_vs_typeclass {
    public interface ResourcePrinterTypeclass {
        MB Print<MonadB, MB>(ResourceWrapper resource, string output) where MonadB: struct, Monad<MB, Unit>;
        MB AcquireResource<MonadB, MB>() where MonadB: struct, Monad<MB, ResourceWrapper>;
    }

    public struct ResourcePrinterTypeclassImpl : ResourcePrinterTypeclass {
        public MB Print<MonadB, MB>(ResourceWrapper resource, string output) where MonadB: struct, Monad<MB, Unit> =>
            default(MonadB).Return(fun(() => resource.Print(output))());
        
        public MB AcquireResource<MonadB, MB>() where MonadB: struct, Monad<MB, ResourceWrapper> =>
            default(MonadB).Return(new ResourceWrapper());
    }
}







|
|



|
|

|
|


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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();
    }
}