junkcode  Check-in [23c2fc6b5b]

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

Overview
Comment:Simplify further.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256:23c2fc6b5bf2d38dc116bf7984ed4547a31ecba2b975838d4961b25397f0442d
User & Date: jaccarmac 2018-01-29 05:57:20
Context
2018-01-29
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
05:45
Switching from Identity to Option solves the Bind type inference issue. check-in: ff0e1f8539 user: jaccarmac tags: trunk
Changes

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

10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
    {
        public static void Main(string[] args)
        {
            var freeProgram = new ResourcePrinterFree<Unit>.Print("Hello, world!", () =>
                new ResourcePrinterFree<Unit>.Return(unit));
            freeProgram.Map(FreeInterpreter.Interpret);

            TypeclassProgram<ResourcePrinterTypeclassUnit, Unit>();
        }

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







|


|




10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
    {
        public static void Main(string[] args)
        {
            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!")));
    }
}

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<MA, A> {
        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 ResourcePrinterTypeclassUnit : ResourcePrinterTypeclass<Option<Unit>, Unit> {
        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 {
        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());
    }
}