Skip to content

Commit 7979273

Browse files
authored
Use strict types for applicatives
1 parent 649bf19 commit 7979273

File tree

1 file changed

+24
-22
lines changed

1 file changed

+24
-22
lines changed

src/FSharpPlus/Functor.fs

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -139,35 +139,32 @@ type Return =
139139

140140
type Apply =
141141
inherit Default1
142-
143-
static member inline ``<*>`` (f: '``Monad<'T->'U>`` , x: '``Monad<'T>`` , [<Optional>]_output: '``Monad<'U>`` , [<Optional>]_mthd:Default2) : '``Monad<'U>`` = Bind.InvokeOnInstance f (fun (x1: 'T->'U) -> Bind.InvokeOnInstance x (fun x2 -> Return.InvokeOnInstance (x1 x2)))
144-
static member inline ``<*>`` (f: '``Applicative<'T->'U>``, x: '``Applicative<'T>``, [<Optional>]_output: '``Applicative<'U>``, [<Optional>]_mthd:Default1) : '``Applicative<'U>`` = ((^``Applicative<'T->'U>`` or ^``Applicative<'T>`` or ^``Applicative<'U>``) : (static member (<*>) : _*_ -> _) f, x)
145142

146-
static member ``<*>`` (f: Lazy<'T->'U> , x: Lazy<'T> , [<Optional>]_output: Lazy<'U> , [<Optional>]_mthd: Apply) = Lazy<_>.Create (fun () -> f.Value x.Value) : Lazy<'U>
147-
static member ``<*>`` (f: seq<_> , x: seq<'T> , [<Optional>]_output: seq<'U> , [<Optional>]_mthd: Apply) = Seq.apply f x : seq<'U>
143+
static member ``<*>`` ((f: Lazy<'T->'U> , x: Lazy<'T> , _output: Lazy<'U>) , [<Optional>]_mthd: Apply) = Lazy<_>.Create (fun () -> f.Value x.Value) : Lazy<'U>
144+
static member ``<*>`` ((f: seq<_> , x: seq<'T> , _output: seq<'U>) , [<Optional>]_mthd: Apply) = Seq.apply f x : seq<'U>
148145
#if !FABLE_COMPILER
149-
static member ``<*>`` (f: IEnumerator<_> , x: IEnumerator<'T> , [<Optional>]_output: IEnumerator<'U> , [<Optional>]_mthd: Apply) = Enumerator.map2 id f x : IEnumerator<'U>
146+
static member ``<*>`` ((f: IEnumerator<_> , x: IEnumerator<'T> , _output: IEnumerator<'U>) , [<Optional>]_mthd: Apply) = Enumerator.map2 id f x : IEnumerator<'U>
150147
#endif
151-
static member ``<*>`` (f: list<_> , x: list<'T> , [<Optional>]_output: list<'U> , [<Optional>]_mthd: Apply) = List.apply f x : list<'U>
152-
static member ``<*>`` (f: _ [] , x: 'T [] , [<Optional>]_output: 'U [] , [<Optional>]_mthd: Apply) = Array.collect (fun x1 -> Array.collect (fun x2 -> [|x1 x2|]) x) f : 'U []
153-
static member ``<*>`` (f: 'r -> _ , g: _ -> 'T , [<Optional>]_output: 'r -> 'U , [<Optional>]_mthd: Apply) = fun x -> f x (g x) : 'U
154-
static member inline ``<*>`` ((a: 'Monoid, f) , (b: 'Monoid, x: 'T) , [<Optional>]_output: 'Monoid * 'U , [<Optional>]_mthd: Apply) = (Plus.Invoke a b, f x) : 'Monoid *'U
148+
static member ``<*>`` ((f: list<_> , x: list<'T> , _output: list<'U>) , [<Optional>]_mthd: Apply) = List.apply f x : list<'U>
149+
static member ``<*>`` ((f: _ [] , x: 'T [] , _output: 'U []) , [<Optional>]_mthd: Apply) = Array.collect (fun x1 -> Array.collect (fun x2 -> [|x1 x2|]) x) f : 'U []
150+
static member ``<*>`` ((f: 'r -> _ , g: _ -> 'T , _output: 'r -> 'U) , [<Optional>]_mthd: Apply) = fun x -> f x (g x) : 'U
151+
static member inline ``<*>`` (((a: 'Monoid, f) , (b: 'Monoid, x: 'T) , _output: 'Monoid * 'U) , [<Optional>]_mthd: Apply) = (Plus.Invoke a b, f x) : 'Monoid *'U
155152
#if !FABLE_COMPILER
156-
static member ``<*>`` (f: Task<_> , x: Task<'T> , [<Optional>]_output: Task<'U> , [<Optional>]_mthd: Apply) = Task.apply f x : Task<'U>
153+
static member ``<*>`` ((f: Task<_> , x: Task<'T> , _output: Task<'U>) , [<Optional>]_mthd: Apply) = Task.apply f x : Task<'U>
157154
#endif
158-
static member ``<*>`` (f: Async<_> , x: Async<'T> , [<Optional>]_output: Async<'U> , [<Optional>]_mthd: Apply) = Async.apply f x : Async<'U>
159-
static member ``<*>`` (f: option<_> , x: option<'T> , [<Optional>]_output: option<'U> , [<Optional>]_mthd: Apply) = Option.apply f x : option<'U>
160-
static member ``<*>`` (f: Result<_,'E> , x: Result<'T,'E> , [<Optional>]_output: Result<'b,'E> , [<Optional>]_mthd: Apply) = Result.apply f x : Result<'U,'E>
161-
static member ``<*>`` (f: Choice<_,'E> , x: Choice<'T,'E> , [<Optional>]_output: Choice<'b,'E> , [<Optional>]_mthd: Apply) = Choice.apply f x : Choice<'U,'E>
162-
static member inline ``<*>`` (KeyValue(a: 'Key, f), KeyValue(b: 'Key, x: 'T), [<Optional>]_output: KeyValuePair<'Key,'U>, [<Optional>]_mthd: Apply) : KeyValuePair<'Key,'U> = KeyValuePair (Plus.Invoke a b, f x)
155+
static member ``<*>`` ((f: Async<_> , x: Async<'T> , _output: Async<'U>) , [<Optional>]_mthd: Apply) = Async.apply f x : Async<'U>
156+
static member ``<*>`` ((f: option<_> , x: option<'T> , _output: option<'U>) , [<Optional>]_mthd: Apply) = Option.apply f x : option<'U>
157+
static member ``<*>`` ((f: Result<_,'E> , x: Result<'T,'E> , _output: Result<'b,'E>) , [<Optional>]_mthd: Apply) = Result.apply f x : Result<'U,'E>
158+
static member ``<*>`` ((f: Choice<_,'E> , x: Choice<'T,'E> , _output: Choice<'b,'E>) , [<Optional>]_mthd: Apply) = Choice.apply f x : Choice<'U,'E>
159+
static member inline ``<*>`` ((KeyValue(a: 'Key, f), KeyValue(b: 'Key, x: 'T), _output: KeyValuePair<'Key,'U>), [<Optional>]_mthd: Apply) : KeyValuePair<'Key,'U> = KeyValuePair (Plus.Invoke a b, f x)
163160

164-
static member ``<*>`` (f: Map<'Key,_> , x: Map<'Key,'T> , [<Optional>]_output: Map<'Key,'U> , [<Optional>]_mthd: Apply) : Map<'Key,'U> = Map (seq {
161+
static member ``<*>`` ((f: Map<'Key,_> , x: Map<'Key,'T> , _output: Map<'Key,'U>) , [<Optional>]_mthd: Apply) : Map<'Key,'U> = Map (seq {
165162
for KeyValue(k, vf) in f do
166163
match Map.tryFind k x with
167164
| Some vx -> yield k, vf vx
168165
| _ -> () })
169166

170-
static member ``<*>`` (f: Dictionary<'Key,_>, x: Dictionary<'Key,'T> , [<Optional>]_output: Dictionary<'Key,'U> , [<Optional>]_mthd: Apply) : Dictionary<'Key,'U> =
167+
static member ``<*>`` ((f: Dictionary<'Key,_>, x: Dictionary<'Key,'T> , _output: Dictionary<'Key,'U>) , [<Optional>]_mthd: Apply) : Dictionary<'Key,'U> =
171168
let dct = Dictionary ()
172169
for KeyValue(k, vf) in f do
173170
match x.TryGetValue k with
@@ -176,19 +173,24 @@ type Apply =
176173
dct
177174

178175
#if !FABLE_COMPILER
179-
static member ``<*>`` (f: Expr<'T->'U>, x: Expr<'T>, [<Optional>]_output: Expr<'U>, [<Optional>]_mthd: Apply) = Expr.Cast<'U> (Expr.Application (f, x))
176+
static member ``<*>`` ((f: Expr<'T->'U>, x: Expr<'T>, _output: Expr<'U>), [<Optional>]_mthd: Apply) = Expr.Cast<'U> (Expr.Application (f, x))
180177
#endif
181-
static member ``<*>`` (f: ('T->'U) ResizeArray, x: 'T ResizeArray, [<Optional>]_output: 'U ResizeArray, [<Optional>]_mthd: Apply) =
178+
static member ``<*>`` ((f: ('T->'U) ResizeArray, x: 'T ResizeArray, _output: 'U ResizeArray), [<Optional>]_mthd: Apply) =
182179
ResizeArray (Seq.collect (fun x1 -> Seq.collect (fun x2 -> Seq.singleton (x1 x2)) x) f) : 'U ResizeArray
183180

184181
static member inline Invoke (f: '``Applicative<'T -> 'U>``) (x: '``Applicative<'T>``) : '``Applicative<'U>`` =
185182
let inline call (mthd : ^M, input1: ^I1, input2: ^I2, output: ^R) =
186-
((^M or ^I1 or ^I2 or ^R) : (static member ``<*>`` : _*_*_*_ -> _) input1, input2, output, mthd)
183+
((^M or ^I1 or ^I2 or ^R) : (static member ``<*>`` : (_*_*_)*_ -> _) (input1, input2, output), mthd)
187184
call(Unchecked.defaultof<Apply>, f, x, Unchecked.defaultof<'``Applicative<'U>``>)
188185

189186
static member inline InvokeOnInstance (f: '``Applicative<'T->'U>``) (x: '``Applicative<'T>``) : '``Applicative<'U>`` =
190187
((^``Applicative<'T->'U>`` or ^``Applicative<'T>`` or ^``Applicative<'U>``) : (static member (<*>) : _*_ -> _) (f, x))
191188

189+
type Apply with
190+
static member inline ``<*>`` ((f: '``Monad<'T->'U>`` , x: '``Monad<'T>`` , _output: '``Monad<'U>`` ), [<Optional>]_mthd:Default2) : '``Monad<'U>`` = Bind.InvokeOnInstance f (fun (x1: 'T->'U) -> Bind.InvokeOnInstance x (fun x2 -> Return.InvokeOnInstance (x1 x2)))
191+
static member inline ``<*>`` ((_: ^t when ^t : null and ^t: struct, _: ^u when ^u : null and ^u: struct, _output: ^r when ^r : null and ^r: struct), _mthd: Default1) = id
192+
static member inline ``<*>`` ((f: '``Applicative<'T->'U>``, x: '``Applicative<'T>``, _output: '``Applicative<'U>``), [<Optional>]_mthd:Default1) : '``Applicative<'U>`` = ((^``Applicative<'T->'U>`` or ^``Applicative<'T>`` or ^``Applicative<'U>``) : (static member (<*>) : _*_ -> _) f, x)
193+
192194
// Functor class ----------------------------------------------------------
193195

194196
type Iterate =
@@ -900,4 +902,4 @@ module internal MonadOps =
900902
#endif
901903
let inline (<*>) f x = Apply.Invoke f x
902904
let inline (<|>) x y = Append.Invoke x y
903-
let inline (>=>) (f: 'a->'``Monad<'b>``) (g: 'b->'``Monad<'c>``) (x: 'a) : '``Monad<'c>`` = f x >>= g
905+
let inline (>=>) (f: 'a->'``Monad<'b>``) (g: 'b->'``Monad<'c>``) (x: 'a) : '``Monad<'c>`` = f x >>= g

0 commit comments

Comments
 (0)