forked from dotnet/fsharp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
939050e
commit f9893b6
Showing
5 changed files
with
92 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
...nformance/DeclarationElements/MemberDefinitions/OverloadingMembers/OverloadsAndSRTPs01.fs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// #Conformance #DeclarationElements #MemberDefinitions #Overloading | ||
// Exotic case from F#+ https://github.com/gusty/FSharpPlus | ||
|
||
module Applicatives = | ||
open System | ||
|
||
type Ap = Ap with | ||
static member inline Invoke (x:'T) : '``Applicative<'T>`` = | ||
let inline call (mthd : ^M, output : ^R) = ((^M or ^R) : (static member Return: _*_ -> _) output, mthd) | ||
call (Ap, Unchecked.defaultof<'``Applicative<'T>``>) x | ||
static member inline InvokeOnInstance (x:'T) = (^``Applicative<'T>`` : (static member Return: ^T -> ^``Applicative<'T>``) x) | ||
static member inline Return (r:'R , _:obj) = Ap.InvokeOnInstance :_ -> 'R | ||
static member Return (_:seq<'a> , Ap ) = fun x -> Seq.singleton x : seq<'a> | ||
static member Return (_:Tuple<'a>, Ap ) = fun x -> Tuple x : Tuple<'a> | ||
static member Return (_:'r -> 'a , Ap ) = fun k _ -> k : 'a -> 'r -> _ | ||
|
||
let inline result (x:'T) = Ap.Invoke x | ||
|
||
let inline (<*>) (f:'``Applicative<'T->'U>``) (x:'``Applicative<'T>``) : '``Applicative<'U>`` = | ||
(( ^``Applicative<'T->'U>`` or ^``Applicative<'T>`` or ^``Applicative<'U>``) : (static member (<*>): _*_ -> _) f, x) | ||
|
||
let inline (+) (a:'Num) (b:'Num) :'Num = a + b | ||
|
||
type ZipList<'s> = ZipList of 's seq with | ||
static member Return (x:'a) = ZipList (Seq.initInfinite (fun _ -> x)) | ||
static member (<*>) (ZipList (f:seq<'a->'b>), ZipList x) = ZipList (Seq.zip f x |> Seq.map (fun (f, x) -> f x)) :ZipList<'b> | ||
|
||
type Ii = Ii | ||
type Idiomatic = Idiomatic with | ||
static member inline ($) (Idiomatic, si) = fun sfi x -> (Idiomatic $ x) (sfi <*> si) | ||
static member ($) (Idiomatic, Ii) = id | ||
let inline idiomatic a b = (Idiomatic $ b) a | ||
let inline iI x = (idiomatic << result) x | ||
|
||
let res1n2n3 = iI (+) (result 0M ) (ZipList [1M;2M;3M]) Ii | ||
let res2n3n4 = iI (+) (result LanguagePrimitives.GenericOne) (ZipList [1 ;2 ;3 ]) Ii | ||
|
||
exit 0 |
26 changes: 26 additions & 0 deletions
26
...nformance/DeclarationElements/MemberDefinitions/OverloadingMembers/RecursiveOverload01.fs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// #Conformance #DeclarationElements #MemberDefinitions #Overloading | ||
// Originally from https://gist.github.com/gusty/b6fac370bff36a665d75 | ||
type FoldArgs<'t> = FoldArgs of ('t -> 't -> 't) | ||
|
||
let inline foldArgs f (x:'t) (y:'t) :'rest = (FoldArgs f $ Unchecked.defaultof<'rest>) x y | ||
|
||
type FoldArgs<'t> with | ||
static member inline ($) (FoldArgs f, _:'t-> 'rest) = fun (a:'t) -> f a >> foldArgs f | ||
static member ($) (FoldArgs f, _:'t ) = f | ||
|
||
let test1() = | ||
let x:int = foldArgs (+) 2 3 | ||
let y:int = foldArgs (+) 2 3 4 | ||
let z:int = foldArgs (+) 2 3 4 5 | ||
let d:decimal = foldArgs (+) 2M 3M 4M | ||
let e:string = foldArgs (+) "h" "e" "l" "l" "o" | ||
let f:float = foldArgs (+) 2. 3. 4. | ||
|
||
let mult3Numbers a b c = a * b * c | ||
let res2 = mult3Numbers 3 (foldArgs (+) 3 4) (foldArgs (+) 2 2 3 3) | ||
() | ||
|
||
// Run the test | ||
test1() | ||
|
||
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters