Пример #1
0
            static MapBuild()
            {
                try
                {
                    var(fullNameMA, nameMA, gensMA) = ClassFunctions.GetTypeInfo <MA>();
                    var(fullNameMB, nameMB, gensMB) = ClassFunctions.GetTypeInfo <MB>();

                    if (nameMA != nameMB)
                    {
                        Default = (MA x, Func <A, B> f) =>
                                  throw new NotSupportedException(
                                            $"Different outer types given for functor, they must match, like Option<A> and Option<B>");
                    }

                    var gens = Enumerable.Concat(gensMA, gensMB).ToArray();

                    Default = ClassFunctions.MakeFunc2 <MA, Func <A, B>, MB>(nameMA, "Map", gens,
                                                                             ("Functor", ""), ("F", ""));

                    if (Default == null)
                    {
                        Default = (MA x, Func <A, B> f) =>
                                  throw new NotSupportedException(
                                            $"Functor{nameMA} or F{nameMA} instance not found for {fullNameMA} (FunctorClass.Map)");
                    }
                }
                catch (Exception e)
                {
                    Error   = Some(Common.Error.New(e));
                    Default = (MA x, Func <A, B> f) => throw e;
                }
            }
Пример #2
0
        static MonadClass()
        {
            try
            {
                var(fullNameMA, nameMA, gensMA) = ClassFunctions.GetTypeInfo <MA>();

                Return = ClassFunctions.MakeFunc1 <A, MA>(nameMA, "Return", gensMA,
                                                          ("MonadReturn", ""), ("MReturn", ""), ("Monad", ""), ("M", ""));

                Fail = ClassFunctions.MakeFunc1 <Error, MA>(nameMA, "Fail", gensMA,
                                                            ("MonadFail", ""), ("MFail", ""), ("Monad", ""), ("M", ""));

                if (Return == null)
                {
                    Return = (A x) =>
                             throw new NotSupportedException(
                                       $"MonadReturn{nameMA}, MReturn{nameMA}, Monad{nameMA} or M{nameMA} , instance not found for {fullNameMA} (MonadClass.Return)");
                }

                if (Fail == null)
                {
                    Fail = (Error x) =>
                           throw new NotSupportedException(
                                     $"MonadFail{nameMA}, MFail{nameMA}, Monad{nameMA} or M{nameMA} , instance not found for {fullNameMA} (MonadClass.Fail)");
                }
            }
            catch (Exception e)
            {
                Error  = Some(Common.Error.New(e));
                Fail   = (Error x) => throw e;
                Return = (A x) => throw e;
            }
        }