Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docsrc/content/abstraction-alternative.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ From .Net/F#
- ``option<'T>``
- ``array<'T>``
- ``seq<'T>``
- ``'T -> 'Alternative``

From F#+

Expand Down Expand Up @@ -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
let r2 = Some 2 <|> Some 1 // first success => Some 2
6 changes: 5 additions & 1 deletion src/FSharpPlus/Control/Alternative.fs
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,16 @@ type Empty =
static member Empty ([<Optional>]_output: option<'T> , [<Optional>]_mthd: Empty ) = None : option<'T>
static member Empty ([<Optional>]_output: voption<'T> , [<Optional>]_mthd: Empty ) = ValueNone : voption<'T>
static member Empty ([<Optional>]_output: list<'T> , [<Optional>]_mthd: Empty ) = [ ] : list<'T>
static member Empty ([<Optional>]_output: 'T [] , [<Optional>]_mthd: Empty ) = [||] : 'T []
static member Empty ([<Optional>]_output: 'T [] , [<Optional>]_mthd: Empty ) = [||] : 'T []

static member inline Invoke () : '``Alternative<'T>`` =
let inline call (mthd: ^M, output: ^R) = ((^M or ^R) : (static member Empty : _*_ -> _) output, mthd)
call (Unchecked.defaultof<Empty>, Unchecked.defaultof<'``Alternative<'T>``> )

static member inline InvokeOnInstance () : '``Alternative<'T>`` = (^``Alternative<'T>`` : (static member Empty : ^``Alternative<'T>``) ()) : '``Alternative<'T>``

type Empty with
static member inline Empty ([<Optional>]_output: 'R -> '``Alternative<'T>``, [<Optional>]_mthd: Empty) = (fun _ -> Empty.Invoke ()) : 'R -> '``Alternative<'T>``

type Append =
inherit Default1
Expand All @@ -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<Append>, x, y)

type Append with
static member inline ``<|>`` (x: 'R -> '``Alt<'T>`` , y , [<Optional>]_mthd: Append ) = fun r -> Append.Invoke (x r) (y r)


type IsAltLeftZero =
Expand Down