Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why can I pass an F# function to a System.Func parameter only in a member method?

Tags:

function

f#

This works:

type MyType () =
    static member MyFn (fn : Func<bool>) = fn.Invoke ()

MyType.MyFn (fun _ -> false)

This does not (error FS0002):

let myFn (fn : Func<bool>) = fn.Invoke ()

myFn (fun _ -> false)

Neither does this (error FS0002):

type MyDU = Fn of Func<bool>

Fn (fun _ -> false)

What is the reason for this rather annoying inconsistency?

like image 439
MiloDC Avatar asked Feb 25 '16 20:02

MiloDC


People also ask

What is a passing F?

F. no. failure (pass/fail option)

What does it mean to get an F on a test?

Author has 267 answers and 164.6K answer views 5y. Depends. My school's handbook says “A-Exceptional, B-Above Average, C-Average, D-Below Average, F-Unsatisfactory”


1 Answers

This behavior is covered by section 8.13.7 (Type-directed Conversions at Member Invocations) of the F# spec, where it states:

Note: These type-directed conversions are primarily for interoperability with existing member-based .NET libraries and do not apply at invocations of functions defined in modules or bound locally in expressions.

like image 169
kvb Avatar answered Sep 23 '22 21:09

kvb