From 9d42ccf598b8e995411397f9e2ac323abae15aba Mon Sep 17 00:00:00 2001 From: Gustavo Leon <1261319+gusty@users.noreply.github.com> Date: Sun, 13 Nov 2022 08:15:15 +0100 Subject: [PATCH] Add explicit type parameters (#510) --- src/FSharpPlus/Operators.fs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/FSharpPlus/Operators.fs b/src/FSharpPlus/Operators.fs index 1879be141..ed15d84b0 100644 --- a/src/FSharpPlus/Operators.fs +++ b/src/FSharpPlus/Operators.fs @@ -294,7 +294,7 @@ module Operators = /// Combines two monoids in one. /// /// Monoid - let inline plus (x: 'Monoid) (y: 'Monoid) : 'Monoid = Plus.Invoke x y + let inline plus< ^Monoid when (Plus or ^Monoid) : (static member ``+`` : ^Monoid * ^Monoid * Plus -> ^Monoid)> (x: 'Monoid) (y: 'Monoid) : 'Monoid = Plus.Invoke x y module Seq = @@ -302,7 +302,7 @@ module Operators = /// Folds all values in the sequence using the monoidal addition. /// /// Monoid - let inline sum (x: seq<'Monoid>) : 'Monoid = Sum.Invoke x + let inline sum< ^Monoid when (Sum or seq< ^Monoid> or ^Monoid) : (static member Sum: seq<'Monoid> * 'Monoid * Sum -> 'Monoid)> (x: seq<'Monoid>) : 'Monoid = Sum.Invoke x // Alternative/Monadplus/Arrowplus ---------------------------------------- @@ -333,7 +333,9 @@ module Operators = /// Common uses of guard include conditionally signaling an error in an error monad and conditionally rejecting the current choice in an Alternative-based parser. /// /// Alternative/Monadplus/Arrowplus - let inline guard x: '``MonadPlus`` = if x then Return.Invoke () else Empty.Invoke () + let inline guard< ^``MonadPlus`` when (Return or ^``MonadPlus``) : + (static member Return: ^``MonadPlus`` * Return -> (unit -> ^``MonadPlus``)) and + (Empty or ^``MonadPlus``) : (static member Empty: ^``MonadPlus`` * Empty -> ^``MonadPlus``)> x : '``MonadPlus`` = if x then Return.Invoke () else Empty.Invoke () // Contravariant/Bifunctor/Profunctor/Invariant --------------------------- @@ -1333,19 +1335,19 @@ module Operators = /// Convert from a byte array value, given options of little-endian, and startIndex /// /// Converter - let inline ofBytesWithOptions (isLtEndian: bool) (startIndex: int) (value: byte[]) = OfBytes.Invoke isLtEndian startIndex value + let inline ofBytesWithOptions< ^T when (OfBytes or ^T) : (static member OfBytes: ^T * OfBytes -> (byte[] * int * bool -> ^T))> (isLtEndian: bool) (startIndex: int) (value: byte[]) : 'T = OfBytes.Invoke isLtEndian startIndex value /// /// Convert from a byte array value, assuming little-endian /// /// Converter - let inline ofBytes (value: byte[]) = OfBytes.Invoke true 0 value + let inline ofBytes< ^T when (OfBytes or ^T) : (static member OfBytes: ^T * OfBytes -> (byte[] * int * bool -> ^T))> (value: byte[]) : 'T = OfBytes.Invoke true 0 value /// /// Convert from a byte array value, assuming big-endian /// /// Converter - let inline ofBytesBE (value: byte[]) = OfBytes.Invoke false 0 value + let inline ofBytesBE< ^T when (OfBytes or ^T) : (static member OfBytes: ^T * OfBytes -> (byte[] * int * bool -> ^T))> (value: byte[]) : 'T = OfBytes.Invoke false 0 value /// /// Convert to a byte array value, assuming little endian @@ -1367,13 +1369,13 @@ module Operators = /// Converts to a value from its string representation. /// /// Converter - let inline parse (value: string) = Parse.Invoke value + let inline parse< ^T when (Parse or ^T) : (static member Parse: ^T * Parse -> (string -> ^T))> (value: string) : 'T = Parse.Invoke value /// /// Converts to a value from its string representation. Returns None if the convertion doesn't succeed. /// /// Converter - let inline tryParse (value: string) = TryParse.Invoke value + let inline tryParse< ^T when (TryParse or ^T) : (static member TryParse: ^T * TryParse -> (string -> ^T option))> (value: string) : 'T option = TryParse.Invoke value // Numerics