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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T17:07:49+00:00 2026-06-03T17:07:49+00:00

type T() = static member (~%)(t : T) = t let t = T()

  • 0
type T() =
    static member (~%)(t : T) = t

let t = T()
let t' = %t // FAILS

The error message says t was expected to be of type Quotation.Expr<'a>.
% is a supposedly valid prefix operator, but is it possible to actually use it?

  • 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-03T17:07:51+00:00Added an answer on June 3, 2026 at 5:07 pm

    The reason why you are seeing this behavior is because F# does not define (~%) with static constraints like most top-level operators. It is defined as a function Quotations.Expr<'a> -> 'a. Hence, the (~%) function (which is an alias for op_Splice) you defined on type T is not resolved by uses of the top-level (~%) operator.

    You can see this by the following FSI interaction:

    > <@ (~%) @>;;
    
      <@ (~%) @>;;
      ^^^^^^^^^^
    
    C:\Users\Stephen\AppData\Local\Temp\stdin(5,1): error FS0030: Value restriction. The value 'it' has been inferred to have generic type
        val it : Expr<(Expr<'_a> -> '_a)>    
    Either define 'it' as a simple data term, make it a function with explicit arguments or, if you do not intend for it to be generic, add a type annotation.
    

    Thus if we redefine the top-level (~%) operator as follows, then your example will compile without error:

    let inline (~%) (x : ^a) = (^a : (static member op_Splice : ^a -> 'b) (x))
    

    but do note that quotation splicing will no longer work:

    let x = <@ 3 @>
    <@ %x @>
    ----^
    error FS0001: The type 'Expr<int>' does not support the operator '~%'
    

    that’s because the original definition of (~%) is treated specially by the compiler for quotation splicing. Indeed, you can see in the Expr and Expr<'T> signatures that those types do not define any operators at all, let alone op_Splice.

    You can see similar results with && and || infix operators. Which can be redefined (mapping to op_BooleanAnd and op_BooleanOr), but unless they are, they are treated specially by the compiler.

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

Sidebar

Related Questions

Why isn't this allowed? type Foo() = static member Bar() = () let inline
I currently have a function: public static Attribute GetAttribute(MemberInfo Member, Type AttributeType) { Object[]
Is there any way to access let bound fields from a static member? The
why does not this code work? type Test() = static member func (a: seq<'a
When running the following code open System open Microsoft.FSharp.Control type Message(id, contents) = static
Let's say i have a class Foo and it has a static member variable
module FSharp= let Point2d (x,y)= Point2d(x,y) let Point3d (x,y,z)= Point3d(x,y,z) type NXOpen.Point3d with static
I have a static member in the base class of type: private static Dictionary<string,
Given the following fragment: type Foo() = static member Test (act : unit ->
Would like to know the c# code to actually retrieve the IP type: Static

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.