Skip to content
Draft
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
24 changes: 19 additions & 5 deletions src/FSharpPlus/Data/Compose.fs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type Compose<'``functorF<'functorG<'t>>``> = Compose of '``functorF<'functorG<'t
/// To be used in Applicative Style expressions, combined with &lt;*&gt;
/// </summary>
/// <category index="1">Functor</category>
static member inline (<!>) (f: 'T -> 'U, x: '``FunctorF<'FunctorG<'T>>``) =
static member inline (<!>) (f: 'T -> 'U, Compose (x: '``FunctorF<'FunctorG<'T>>``)) =
Compose (map (map f: '``FunctorG<'T>`` -> '``FunctorG<'U>``) x : '``FunctorF<'FunctorG<'U>>``)

// Applicative
Expand All @@ -32,15 +32,15 @@ type Compose<'``functorF<'functorG<'t>>``> = Compose of '``functorF<'functorG<'t
/// Sequences two composed applicatives left-to-right, discarding the value of the first argument.
/// </summary>
/// <category index="2">Applicative</category>
static member inline ( *>) (x: '``FunctorF<'FunctorG<'T>>``, y: '``FunctorF<'FunctorG<'U>>``) : '``FunctorF<'FunctorG<'U>>`` =
((fun (_: 'T) (k: 'U) -> k) <!> x : '``FunctorF<'FunctorG<'U -> 'U>>``) <*> y
static member inline ( *>) (Compose (x: '``FunctorF<'FunctorG<'T>>``), Compose (y: '``FunctorF<'FunctorG<'U>>``)) : Compose<'``FunctorF<'FunctorG<'U>>``> =
(Apply.Invoke << Map.Invoke (Apply.Invoke << Map.Invoke (fun _ k -> k))) x y |> Compose

/// <summary>
/// Sequences two composed applicatives left-to-right, discarding the value of the second argument.
/// </summary>
/// <category index="2">Applicative</category>
static member inline (<* ) (x: '``FunctorF<'FunctorG<'U>>``, y: '``FunctorF<'FunctorG<'T>>``): '``FunctorF<'FunctorG<'U>>`` =
((fun (k: 'U) (_: 'T) -> k) <!> x : '``FunctorF<'FunctorG<'T -> 'U>>``) <*> y
static member inline (<* ) (Compose (x: '``FunctorF<'FunctorG<'U>>``), Compose (y: '``FunctorF<'FunctorG<'T>>``)) : Compose<'``FunctorF<'FunctorG<'U>>``> =
(Apply.Invoke << Map.Invoke (Apply.Invoke << Map.Invoke (fun k _ -> k))) x y |> Compose

static member inline Lift2 (f: 'T -> 'U -> 'V, Compose (x: '``ApplicativeF<'ApplicativeG<'T>``), Compose (y: '``ApplicativeF<'ApplicativeG<'U>``)) =
Compose (Lift2.Invoke (Lift2.Invoke f: '``ApplicativeG<'T>`` -> '``ApplicativeG<'U>`` -> '``ApplicativeG<'V>``) x y: '``ApplicativeF<'ApplicativeG<'V>``)
Expand All @@ -56,6 +56,20 @@ type Compose<'``functorF<'functorG<'t>>``> = Compose of '``functorF<'functorG<'t
static member inline (<.>) (Compose (f: '``ApplicativeF<'ApplicativeG<'T -> 'U>``), Compose (x: '``ApplicativeF<'ApplicativeG<'T>``)) =
Compose ((((<.>) : '``ApplicativeG<'T -> 'U>`` -> '``ApplicativeG<'T>`` -> '``ApplicativeG<'U>``) <!> f: '``ApplicativeF<'ApplicativeG<'T> -> 'ApplicativeG<'U>`` ) <.> x: '``ApplicativeF<'ApplicativeG<'U>``)

/// <summary>
/// Applies two composed applicatives left-to-right in a non-sequential way, discarding the value of the first argument.
/// </summary>
/// <category index="2">Applicative</category>
static member inline ( .>) (Compose (x: '``FunctorF<'FunctorG<'T>>``), Compose (y: '``FunctorF<'FunctorG<'U>>``)) : Compose<'``FunctorF<'FunctorG<'U>>``> =
(ZipApply.Invoke << Map.Invoke (ZipApply.Invoke << Map.Invoke (fun _ k -> k))) x y |> Compose

/// <summary>
/// Applies two composed applicatives left-to-right in a non-sequential way, discarding the value of the second argument.
/// </summary>
/// <category index="2">Applicative</category>
static member inline (<. ) (Compose (x: '``FunctorF<'FunctorG<'U>>``), Compose (y: '``FunctorF<'FunctorG<'T>>``)) : Compose<'``FunctorF<'FunctorG<'U>>``> =
(ZipApply.Invoke << Map.Invoke (ZipApply.Invoke << Map.Invoke (fun k _ -> k))) x y |> Compose

static member inline Map2 (f: 'T -> 'U -> 'V, Compose (x: '``ApplicativeF<'ApplicativeG<'T>``), Compose (y: '``ApplicativeF<'ApplicativeG<'U>``)) =
Compose (Map2.Invoke (Map2.Invoke f: '``ApplicativeG<'T>`` -> '``ApplicativeG<'U>`` -> '``ApplicativeG<'V>``) x y: '``ApplicativeF<'ApplicativeG<'V>``)

Expand Down
31 changes: 27 additions & 4 deletions src/FSharpPlus/Operators.fs
Original file line number Diff line number Diff line change
Expand Up @@ -217,13 +217,13 @@ module Operators =
/// Sequences two applicatives left-to-right, discarding the value of the first argument.
/// </summary>
/// <category index="2">Applicative</category>
let inline ( *>) (x: '``Applicative<'T>``) (y: '``Applicative<'U>``) : '``Applicative<'U>`` = ((fun (_: 'T) (k: 'U) -> k) <!> x : '``Applicative<'U->'U>``) <*> y
let inline ( *>) (x: '``Applicative<'T>``) (y: '``Applicative<'U>``) : '``Applicative< 'U>`` = ((fun (_: 'T) (k: 'U) -> k) <!> x : '``Applicative<'U->'U>``) <*> y

/// <summary>
/// Sequences two applicatives left-to-right, discarding the value of the second argument.
/// </summary>
/// <category index="2">Applicative</category>
let inline (<* ) (x: '``Applicative<'U>``) (y: '``Applicative<'T>``) : '``Applicative<'U>`` = ((fun (k: 'U) (_: 'T) -> k ) <!> x : '``Applicative<'T->'U>``) <*> y
let inline (<* ) (x: '``Applicative<'U>``) (y: '``Applicative<'T>``) : '``Applicative< 'U>`` = ((fun (k: 'U) (_: 'T) -> k ) <!> x : '``Applicative<'T->'U>``) <*> y

/// <summary>
/// Transforms an alternative value (which has the notion of success/failure) to an alternative
Expand Down Expand Up @@ -262,14 +262,37 @@ module Operators =
/// Applies two applicatives left-to-right in a non-sequential way, discarding the value of the first argument.
/// </summary>
/// <category index="2">Applicative</category>
let inline (.>) (x: '``ZipApplicative<'T>``) (y: '``ZipApplicative<'U>``) : '``ZipApplicative<'U>`` = ((fun (_: 'T) (k: 'U) -> k) <!> x : '``ZipApplicative<'U->'U>``) <.> y
let inline (.>) (x: '``ZipApplicative<'T>``) (y: '``ZipApplicative<'U>``) : '``ZipApplicative< 'U>`` = ((fun (_: 'T) (k: 'U) -> k) <!> x : '``ZipApplicative<'U->'U>``) <.> y

/// <summary>
/// Applies two applicatives left-to-right in a non-sequential way, discarding the value of the second argument.
/// </summary>
/// <category index="2">Applicative</category>
let inline (<.) (x: '``ZipApplicative<'U>``) (y: '``ZipApplicative<'T>``) : '``ZipApplicative<'U>`` = ((fun (k: 'U) (_: 'T) -> k ) <!> x : '``ZipApplicative<'T->'U>``) <.> y
let inline (<.) (x: '``ZipApplicative<'U>``) (y: '``ZipApplicative<'T>``) : '``ZipApplicative< 'U>`` = ((fun (k: 'U) (_: 'T) -> k ) <!> x : '``ZipApplicative<'T->'U>``) <.> y

/// <summary>
/// Sequences two nested applicatives left-to-right, discarding the value of the first argument.
/// </summary>
/// <category index="2">Applicative</category>
let inline ( **>) (x: '``Applicative1<Applicative2<'T>>``) (y: '``Applicative1<Applicative2<'U>>``) : '``Applicative1<Applicative2< 'U>>`` = (Map.Invoke ( *>) x) <*> y

/// <summary>
/// Applies two nested applicatives left-to-right, discarding the value of the first argument.
/// The outer applicative is non-sequential (zip-like), while the inner one is sequential.
/// </summary>
let inline ( .*>) (x: '``ZipApplicative<Applicative<'T>>``) (y: '``ZipApplicative<Applicative<'U>>``) : '``ZipApplicative1<Applicative< 'U>>`` = (Map.Invoke ( *>) x) <.> y

/// <summary>
/// Applies two nested applicatives left-to-right, discarding the value of the first argument.
/// The outer applicative is sequential, while the inner one is non-sequential (zip-like).
/// </summary>
let inline ( *.>) (x: '``Applicative<ZipApplicative<'T>>``) (y: '``Applicative1<ZipApplicative<'U>>``) : '``Applicative1<ZipApplicative< 'U>>`` = (Map.Invoke ( .>) x) <*> y

/// <summary>
/// Applies two nested applicatives left-to-right in a non-sequential way, discarding the value of the first argument.
/// </summary>
let inline ( ..>) (x: '``ZipApplicative1<ZipApplicative2<'T>>``) (y: '``ZipApplicative1<ZipApplicative2<'U>>``) : '``ZipApplicative1<ZipApplicative2< 'U>>`` = (Map.Invoke ( .>) x) <.> y

/// <summary>
/// Applies 2 lifted arguments to a non-lifted function with pointwise and/or parallel semantics.
/// Operator version of 'map2'.
Expand Down
Loading