Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7980823
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T10:11:17+00:00 2026-06-04T10:11:17+00:00

If I have a C# class with implicit conversion to double, like so: public

  • 0

If I have a C# class with implicit conversion to double, like so:

public class Parameter
{
    private double _value;
    public Parameter(double value) { _value = value }
    public static implicit operator double(Parameter p) { return _value; }
}

F# doesn’t like me trying to use it as if it were a float:

let a = Parameter(4.0)
let b = Parameter(2.0)
let c = a * Math.Sin(b) <-- 'expected float, here Parameter'

Is there any way to do this (I’m guessing there isn’t, based on this question/answer), and if not, what would be a decent workaround?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T10:11:19+00:00Added an answer on June 4, 2026 at 10:11 am

    F# does not perform implicit conversions, but it allows you to define an explicit operator to run them. See the kvb’s answer to a previous question:

    let inline (!>) (x:^a) : ^b = ((^a or ^b) : (static member op_Implicit : ^a -> ^b) x) 
    

    This is using statically resolved type parameters to say that either the input or the result needs to provide implicit conversion operator – these are compiled to methods named op_Implicit, so the F# compiler checks for a static method with this special name.

    Using the !> operator, you can now explicitly say where you want to convert Parameter to a float (two times) in your code sample like this:

    let a = Parameter(4.0) 
    let b = Parameter(2.0) 
    let c = !> a * Math.Sin(!> b)
    

    I think the main reason for not allowing implicit conversions in F# is that it would make the type inference a bit more difficult and it would be hard for the compiler to give good error messages.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class with a templated constructor for implicit move conversion, however this
I would like to prefer a certain implicit conversion sequence over another. I have
I have class A: public B { ...} vector<A*> v; I want to do
I have class Fred { public: void inspect() const {}; void modify(){}; }; int
I have a problem understanding why a certain implicit conversion is not working as
I have the following class structure: public class A : AInterface { } public
I have a custom data type called StudentID , which has an implicit conversion
i have a problem about conversion of type using overload of operator, here i
I have a c# data class defined with an inheritance chain that looks like
I have a templated class holding a value. Is it possible to add a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.