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 6347613
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T21:15:07+00:00 2026-05-24T21:15:07+00:00

Leaving aside whether we should use units of measure for unitless concepts like angles,

  • 0

Leaving aside whether we should use units of measure for unitless concepts like angles, suppose I have define degree and radian units in F#

type [<Measure>] degree =
    static member ToRadians (d:float<degree>) : float<radian> = d * (Math.PI * 1.<radian>) / 180.0<degree>
and [<Measure>] radian =
    static member ToDegrees (r:float<radian>) : float<degree> = r * 180.0<degree> / (Math.PI * 1.<radian>)

I can use them relatively easily like

4.0<degree> |> degree.ToRadians

It seems like extension members would be even handier. So I could just say

let d = 4.0<degree>
let r = d.ToRadians()

But I can’t define the extension member the obvious way

type float<degree> with
    member degrees.ToRadians() = degree.ToRadians(degrees)

… this gets me the following error

error FS0010: Unexpected identifier in type name. Expected infix operator, quote symbol or other token.

Is there a syntactic trick for extension members on units of measure in F#, or is the feature supported?

  • 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-05-24T21:15:08+00:00Added an answer on May 24, 2026 at 9:15 pm

    F# extension members are different from C# extension members in that you can’t define extensions of constructed generic types. For instance, you can define extensions on seq<'t>, but not seq<int>. In other words, extension members really act like members of the type, rather than static methods. This applies to measure types too, so you can’t define an extension on float<degree>, but you can define an extension on float<[<Measure>]'u>:

    type float<[<Measure>]'u> with
        member f.Squared() = f * f
    
    [<Measure>]
    type m
    
    let area = 2.0<m>.Squared()
    

    However, I don’t see how this helps you in your case…

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

Sidebar

Related Questions

(Leaving aside the question of should you have them at all.) I have always
Leaving aside the question of whether you should serve single or multiple stylesheets, assuming
Leaving aside semantics, meanings, proper and common use cases of PUT and POST (which
In the test below, the Bar and Baz blocks contain identical specs. Leaving aside
I have a database helper object. It is important I close it when leaving
I was wondering why getRelativeTimeSpanString needs a context? (leaving the puns aside) public static
I wonder which option is more stable (leaving performance aside) and is more widely
(Leaving aside hair-splitting about if this is integration-testing or unit-testing.) I would rather first
I have the following models (simplified leaving all other fields out, focusing on primary
According to [MSDN: Array usage guidelines]( http://msdn.microsoft.com/en-us/library/k2604h5s(VS.71).aspx) : Array Valued Properties You should use

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.