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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:00:16+00:00 2026-05-23T14:00:16+00:00

I tried the following: let inline (|OpAdd|_|) (aty:Type, x:obj, y:obj) = if aty.Equals(typeof<‘a>) then

  • 0

I tried the following:

let inline (|OpAdd|_|) (aty:Type, x:obj, y:obj) =
    if aty.Equals(typeof<'a>) then Some(box ((unbox<'a> x) + (unbox<'a> y)))
    else None

//FSI given signature: 
//val inline ( |OpAdd|_| ) : Type * obj * obj -> obj option

Which gives no warnings or errors, but I can’t figure out how to pass the explicit type argument at the call site and it seems that 'a is always inferred as int.

When I try to place the explicit parameter in the definition, I get a couple warnings and errors:

let inline (|OpAdd|_|)<'a> (aty:Type, x:obj, y:obj) =
    if aty.Equals(typeof<'a>) then Some(box ((unbox<'a> x) + (unbox<'a> y)))
    else None

warning FS1189: Type parameters must be placed directly adjacent to the type name, e.g.       "type C<'T>", not     type "C   <'T>"

error FS0001: The declared type parameter 'a' cannot be used here since the type parameter cannot be resolved at compile time

Is it possible for active patterns to have explicit type parameters? If so how do I define and use them?

  • 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-23T14:00:17+00:00Added an answer on May 23, 2026 at 2:00 pm

    I’m not sure whether there is a clean way to do this (probably not, but I may be wrong).

    As a dirty workaround, you can add a dummy parameter of type 'T (when working with primitive types that have easy-to-create values) or of type Expr<'T> (when you don’t really want to create an instance). Then you can use the pattern with some dummy parameter that specifies the type:

    let inline (|OpAdd|_|) (e:Expr<'T>) (aty:Type, x:obj, y:obj) =
        if aty.Equals(typeof<'T>) then Some(box ((unbox<'T> x) + (unbox<'T> y)))
        else None
    
    let dummy<'T> : 'T = failwith "!"
    
    match (typeof<float>, box 1.1, box 2.1) with 
    | OpAdd <@ dummy<int> @> res -> res
    | OpAdd <@ dummy<float> @> res -> res
    | _ -> null
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I tried following some of the code from here and here , but I
I have tried the following: :let @0 = system('perl /home/hermann/hi.pl') :echo @0 Having hi.pl
I've tried the following code in VS2010: open System.Security.Cryptography let rsaTest1 = let ecKey
I tried initializing an int64 variable in the following way : let k:int64 =
I am getting trouble with the following matter.Let's say, I have some string in
Tried following the instructions here: How to use Google app engine with my own
I tried following the instruction s but can't get the plugin to work, the
I tried following the gradle manual with their example like this but copyJars is
I tried following the answer here how to override a task making it depend
I tried following the following example to make an HTTP link in my TextView

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.