Skip to content
This repository has been archived by the owner on Jan 3, 2023. It is now read-only.

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

Closed
devjuice opened this issue Jun 17, 2016 · 4 comments

Comments

@devjuice
Copy link

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!

@dsyme
Copy link
Contributor

dsyme commented Jun 18, 2016

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.

@dsyme
Copy link
Contributor

dsyme commented Jun 18, 2016

It's a good question - it may make sense to get the answer recorded on stack overflow?

@devjuice
Copy link
Author

Thank you for your quick answer. I just posted the answer to stackoverflow.

May I ask why implicit insertion of flexibility doesn't apply to record fields? :-)

@dsyme
Copy link
Contributor

dsyme commented Jun 21, 2016

@devjuice Technically speaking it could. Please add a request at http://fslang.uservoice..com.

One view is that it might be seen to be odd to introduce genericity at points where the equivalent genericity can't be written manually by adding constrained type variables. As of F# 2.0, record fields can't themselves be generic (prior to that we did allow this - and it was a major source of complication that was essentially never used except code ported from OCaml)

@dsyme dsyme closed this as completed Jun 28, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants