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

  • Home
  • SEARCH
  • 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 7830897
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T11:27:23+00:00 2026-06-02T11:27:23+00:00

Why do i get errors when I write this kind of pattern matching :

  • 0

Why do i get errors when I write this kind of pattern matching :

type t = A of int | B of float

let f = function
        | (A i | B f) -> true
        | _ -> false

or

let f = function
        | A i | B f -> true
        | _ -> false

Error: Variable f must occur on both sides of this | pattern

let f = function
        | (A i | B i) -> true
        | _ -> false

or

let f = function
        | A i | B i -> true
        | _ -> false

Error: This pattern matches values of type ints of type float
but a pattern was expected which matches value

  • 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-02T11:27:28+00:00Added an answer on June 2, 2026 at 11:27 am

    If you provide a single right-hand side for multiple patterns (as you do), OCaml requires that the patterns consistently bind to pattern variables.

    In the first situation,

    match ... with
      | A i | B f -> ...
      ...
    

    the patterns don’t agree on the variables they bind to: the first pattern binds to i, while the second binds to f.

    In the second situation,

    match ... with
      | A i | B i -> ...
      ...
    

    the patterns don’t agree on the type of values to bind to their variables: the first pattern binds a value of type int to i, while the second binds a value of type float to i.

    The only way in which these two pattern can consistently bind to variables is not to bind to any variables at all:

    match ... with
      | A _ | B _ -> ...
      ...
    

    The complete example then becomes

    type t = A of int | B of float
    
    let f = function
      | A _ | B _ -> true
      | _ -> false
    

    (But note that the last arm of the pattern match is superfluous as the first two pattern already exhaustively match all values of your type t. Hence, we get:

    let f = function
      | A _ | B _ -> true
    

    This of course is equivalent to writing let f _ = true.)

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

Sidebar

Related Questions

When retrieving packages with Cabal, I frequently get errors with this message: user error
When I attempt to open a file to write, I get an error: Ada.IO_Exceptions.Name_Error
I tend to get errors such as: Fatal error: Cannot redeclare get_raw_data_list() (previously declared
When I run the test suite of django I get errors on the auth
I want to do the following,but I get errors: procedure JumpToCodeCave(CurrentLocation:DWORD;Destination:Pointer;out_JmpBack:Pointer); var calc:DWORD; jmppatch:Array[0..3]
when I try to create arrays in my script I get errors. id[1]=string2; would
Trying to build a legacy code in VS2005 and get errors in VC header
Magento 1.4.2 Having compilation errors and the page doesn't render. I get errors but
I am using [ http://validator.w3.org/][1] for markup validation and I continue to get errors
I'm trying to do multithread uploads, but get errors. I guessed that maybe it's

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.