Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When a function with seq type parameter is a record field, it won't accept list or array any more

Tags:

f#

Please see the below code.

let x = Seq.head [1.0; 2.0]  // This is ok.

type Func<'T> = { f: seq<'T> -> 'T }

let func = { f = Seq.head }

// Compilation error: This expression was expected to have type seq<obj> but here has type 'a list
let y = func.f [1.0; 2.0]

let z = func.f ([1.0; 2.0] |> List.toSeq)  // This is ok.

I don't understand why Seq.head and fund.f behavior differently here. It looks like a compiler bug to me. However, if this is by design, can anyone help explain a little bit to me? Thanks a lot!

like image 698
appthumb Avatar asked Jun 19 '16 00:06

appthumb


1 Answers

The below is the answer from Don Syme (github.com/fsharp):

This is by design. The rule called "14.4.3 Implicit Insertion of Flexibility for Uses of Functions and Members" is only applied to uses of functions and members, not uses of record fields.

like image 178
appthumb Avatar answered Sep 24 '22 05:09

appthumb