-
Notifications
You must be signed in to change notification settings - Fork 847
Open
Description
Partial application doesn't work as expected when implicit cast to Func<_> takes place
Repro steps
Provide the steps required to reproduce the problem:
open System
let partial () =
let mutable acc = 0
fun () ->
acc <- acc + 1
acc
let test1 (f: Func<unit, int>) =
fun arg ->
f.Invoke(arg)
let test2 (f: unit -> int) =
fun arg ->
f arg
[<EntryPoint>]
let main argv =
let invoker1 = test1 (partial ())
let invoker2 = test2 (partial ())
[ invoker1 (); invoker1 (); invoker1 () ] |> printfn "%A"
[ invoker2 (); invoker2 (); invoker2 () ] |> printfn "%A"
0Expected behavior
Output
[1; 2; 3]
[1; 2; 3]
Expected decompiled code:
FSharpFunc<Unit, int> invoker1 = (FSharpFunc<Unit, int>) new Program.invoker1@19-1(new Func<Unit, int>(Program.partial()));
FSharpFunc<Unit, int> invoker2 = (FSharpFunc<Unit, int>) new Program.invoker2@20(Program.partial());Actual behavior
Output
[1; 1; 1]
[1; 2; 3]
Partial application doesn't work correctly with invoker 1. Here is decompiled code:
FSharpFunc<Unit, int> invoker1 = (FSharpFunc<Unit, int>) new Program.invoker1@19-1(new Func<Unit, int>((object) null, __methodptr(Invoke)));
FSharpFunc<Unit, int> invoker2 = (FSharpFunc<Unit, int>) new Program.invoker2@20(Program.partial());Known workarounds
Extract partial applied function to the variable:
let x = partial ()
let invoker1 = test1 xRelated information
Provide any related information (optional):
- .NET SDK 10.0.101
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
New