diff --git a/docsrc/content/abstraction-alternative.fsx b/docsrc/content/abstraction-alternative.fsx index 884c5955c..04dbd8888 100644 --- a/docsrc/content/abstraction-alternative.fsx +++ b/docsrc/content/abstraction-alternative.fsx @@ -59,6 +59,7 @@ From .Net/F# - ``option<'T>`` - ``array<'T>`` - ``seq<'T>`` + - ``'T -> 'Alternative`` From F#+ @@ -157,4 +158,4 @@ let r6 = map string (Just 6) // But not always the Monoidal behaviour is the same let r3 = Some 2 ++ Some 1 // addition => Some 3 -let r2 = Some 2 <|> Some 1 // first success => Some 2 \ No newline at end of file +let r2 = Some 2 <|> Some 1 // first success => Some 2 diff --git a/src/FSharpPlus/Control/Alternative.fs b/src/FSharpPlus/Control/Alternative.fs index 1e961e55a..23299b3b4 100644 --- a/src/FSharpPlus/Control/Alternative.fs +++ b/src/FSharpPlus/Control/Alternative.fs @@ -24,7 +24,7 @@ type Empty = static member Empty ([]_output: option<'T> , []_mthd: Empty ) = None : option<'T> static member Empty ([]_output: voption<'T> , []_mthd: Empty ) = ValueNone : voption<'T> static member Empty ([]_output: list<'T> , []_mthd: Empty ) = [ ] : list<'T> - static member Empty ([]_output: 'T [] , []_mthd: Empty ) = [||] : 'T [] + static member Empty ([]_output: 'T [] , []_mthd: Empty ) = [||] : 'T [] static member inline Invoke () : '``Alternative<'T>`` = let inline call (mthd: ^M, output: ^R) = ((^M or ^R) : (static member Empty : _*_ -> _) output, mthd) @@ -32,6 +32,8 @@ type Empty = static member inline InvokeOnInstance () : '``Alternative<'T>`` = (^``Alternative<'T>`` : (static member Empty : ^``Alternative<'T>``) ()) : '``Alternative<'T>`` +type Empty with + static member inline Empty ([]_output: 'R -> '``Alternative<'T>``, []_mthd: Empty) = (fun _ -> Empty.Invoke ()) : 'R -> '``Alternative<'T>`` type Append = inherit Default1 @@ -53,6 +55,8 @@ type Append = let inline call (mthd: ^M, input1: ^I, input2: ^I) = ((^M or ^I) : (static member ``<|>`` : _*_*_ -> _) input1, input2, mthd) call (Unchecked.defaultof, x, y) +type Append with + static member inline ``<|>`` (x: 'R -> '``Alt<'T>`` , y , []_mthd: Append ) = fun r -> Append.Invoke (x r) (y r) type IsAltLeftZero =