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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:47:10+00:00 2026-05-22T18:47:10+00:00

I defined the active pattern Expression as follows: let (|Expression|_|) expression _ = Some(expression)

  • 0

I defined the active pattern “Expression” as follows:

let (|Expression|_|) expression _ = Some(expression)

Now I’m trying to use it in this way:

match () with
| Expression((totalWidth - wLeft - wRight) / (float model.Columns.Count - 0.5)) cw
    when cw <= wLeft * 4. && cw <= wRight * 4. ->
        cw
| Expression((totalWidth - wLeft) / (float model.Columns.Count - .25)) cw
    when cw <= wLeft * 4. && cw > wRight * 4. ->
        cw
| Expression((totalWidth - wRight) / (float model.Columns.Count - .25)) cw
    when cw > wLeft * 4. && cw <= wRight * 4. ->
        cw
| Expression(totalWidth / float model.Columns.Count) cw
    when cw > wLeft * 4. && cw > wRight * 4. ->
        cw
| _ -> System.InvalidProgramException() |> raise

But this results in “error FS0010: Unexpected symbol ‘-‘ in pattern”. Is that fixable?

What am I trying to do is to write clearly a solution to the following equation:

max(wl – cw * .25, 0) + max(wr – cw * .25) + cw * columnCount = ActualWidth

where cw is the only variable.

Can you suggest any better way?

  • 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-22T18:47:10+00:00Added an answer on May 22, 2026 at 6:47 pm

    The langauge of expressions that can be used as arguments for parameterized active patterns is limited in some ways. As far as I can tell, the F# specification doesn’t say that explicitly, but the grammar suggests that it must be possible to parse the argument expression as pat-param (page 90):

    pat-param :=
        | const
        | long-ident
        | [ pat-param ; … ; pat-param ]
        | ( pat-param, …, pat-param )
        | long-ident pat-param
        | pat-param : type
        | <@ expr @>
        | <@@ expr @@>
        | null

    So, I think you’ll need to write your pattern matching differently. You could turn the expressions into ordinary arguments of the match construct and write something like this:

    match 
      (totalWidth - wLeft - wRight) / (float model.Columns.Count - 0.5),
      (totalWidth - wLeft) / (float model.Columns.Count - .25),
      (totalWidth - wRight) / (float model.Columns.Count - .25)
    with
    | cw1, _, _ when cw1 <= wLeft * 4. && cw1 <= wRight * 4. -> cw1
    | _, cw2, _ when cw2 <= wLeft * 4. && cw2 > wRight * 4. -> cw2
    | _, _, cw3 when cw3 > wLeft * 4. && cw3 <= wRight * 4. -> cw3
    | _ -> totalWidth / float model.Columns.Count
    

    If the pattern used in the expression is always the same, you could also use active pattern like:

    let (|Calculate|) w p _ =
      (totalWidth - w) / (float model.Columns.Count - p)
    

    … and then write something like:

    let wDif = wLeft - wRight
    match () with
    | Calculate wDif 0.5 cw -> cw
    | Calculate wLeft 0.25 cw -> cw
    // .. etc.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I defined a class named nth_best_parse this way: class nth_best_parse { public: int traversal;
I established a connection with a client this way: gen_tcp:listen(1234,[binary,{packet,0},{reuseaddr,true},{active,false},{recbuf,2048}]). This code performs message
I have a div (id=tabContainer) where I defined some css like below: #tabContainer .ui-state-active
How can I style my buttons to use my defined down ( :active )
I have some time defined from my database, and this is how it looks:
I defined a Window in WPF, into this one I put a stack panel
I have a div with the following CSS class defined: <div class=ui-button ui-state-active>bla bla
I have a class here that is defined like this: struct USERFPOINT { POINTFLOAT
I have a modal box with a defined height. Inside of this box there
This is a simple question regarding $(this) and how it is defined and redefined

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.