Show / Hide Table of Contents

    Enum Never

    Represents an uninhabitable type.
    Namespace: Maki
    Assembly: Maki.dll
    Syntax
    public enum Never
    Examples
    Never is impossible to instantiate, thus it can be use to denote absence of a value. The following example shows two use-cases of Never: explicitly showing a method does not return and as a generic type argument to remove the type option.
    using Maki;
    using System;
    
    namespace Samples
    {
        class Program
        {
            // This function never returns
            static Never Fail(string message)
            {
                throw new Exception(message);
            }
    
            // This function also never returns
            static Never LoopForever()
            {
                while (true)
                { }
            }
    
            // Assume a generic library method which expects an Either<T, U>
            static void NeedsGenericEither<T, U>(Either<T, U> either)
            {
                // ...
            }
    
            static void Main(string[] args)
            {
                // We can remove a type from Either by providing Never
                Either<int, Never> either = 42;
    
                NeedsGenericEither(either);
            }
        }
    }
    • Improve this Doc
    • View Source
    Back to top Generated by DocFX