New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generic struct type whose fields are all unmanaged types is unmanaged #692

Open
dzmitry-lahoda opened this Issue Sep 10, 2018 · 0 comments

Comments

Projects
None yet
2 participants
@dzmitry-lahoda

dzmitry-lahoda commented Sep 10, 2018

Generic struct type whose fields are all unmanaged types is unmanaged

A non-generic struct type whose fields are all unmanaged types is unmanaged.

into

A generic struct type whose fields are all unmanaged types is unmanaged.

as

The unmanaged constraint on generic type T enforces the type to be an 'unmanaged' struct that does not recursively contain reference type fields.

as for cases

type Cell<'T when 'T: unmanaged> =
    struct
        val element: 'T
        val next: nativeptr<Cell<'T>>
    end    

type UnmanagedCell<'T when 'T: unmanaged> =
    struct
    end  

[<EntryPoint>]
let main argv =
    let fine = UnmanagedCell<int>()
    let FS0001 = UnmanagedCell<UnmanagedCell<int>>()
    0

The existing way of approaching this problem in F# is prevent compilation with error

error FS0001: A generic construct requires that the type 'X' is an unmanaged type

I have asked the question on SO and found that it is F# limitation, not CLR.

Pros and Cons

See Related suggestions

Extra information

Related suggestions:
dotnet/csharplang#1504
dotnet/csharplang#1649

Affidavit (please submit!)

Please tick this by placing a cross in the box:

  • [x ] This is not a question (e.g. like one you might ask on stackoverflow) and I have searched stackoverflow for discussions of this issue
  • I have searched both open and closed suggestions on this site and believe this is not a duplicate
  • This is not something which has obviously "already been decided" in previous versions of F#. If you're questioning a fundamental design decision that has obviously already been taken (e.g. "Make F# untyped") then please don't submit it.

Please tick all that apply:

  • This is not a breaking change to the F# language design
  • I or my company would be willing to help implement and/or test this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment