Skip to content

Conversions of char->decimal, string->nativeint, and string->unativeint #1040

@Happypig375

Description

@Happypig375

Conversions of char->decimal, string->nativeint, and string->unativeint

let a = char 48m // Sure
let b = decimal a // error FS0001: The type 'char' does not support a conversion to the type 'decimal'

let c = LanguagePrimitives.ExplicitDynamic<string, nativeint> "2" // Works although warning FS1204: This function is for use by dynamic invocations of F# code and should not be used directly
let d = nativeint "2" // error FS0001: The type 'string' does not support a conversion to the type 'nativeint'

let e = LanguagePrimitives.ExplicitDynamic<string, unativeint> "2" // Works although warning FS1204: This function is for use by dynamic invocations of F# code and should not be used directly
let f = unativeint "2" // error FS0001: The type 'string' does not support a conversion to the type 'unativeint'

I propose we stop being inconsistent and add these 3 conversions.

The existing way of approaching this problem in F# is #nowarn "1204", or having to write conversion functions by ourselves.

Pros and Cons

The advantages of making this adjustment to F# are

  1. Consistency
  2. Convenience
  3. Conciseness

The disadvantages of making this adjustment to F# are that (insert the reason for specifically excluding these 3 conversions as written in https://github.com/dotnet/fsharp/blob/954210d1e8590b708801b2e9f70717f09979b9c0/src/fsharp/ConstraintSolver.fs#L1448-L1451).

Extra information

Estimated cost (XS, S, M, L, XL, XXL): XS

Related suggestions: #1030 - Subtraction of two chars

Affidavit (please submit!)

Please tick this by placing a cross in the box:

  • 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

For Readers

If you would like to see this issue implemented, please click the 👍 emoji on this issue. These counts are used to generally order the suggestions by engagement.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions