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

The Archive Base Latest Questions

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

The following F# code works as I expected, printing `Matched as ‘A’: let (|Char|_|)

  • 0

The following F# code works as I expected, printing `Matched as ‘A’:

let (|Char|_|) convf = function
    | LazyList.Nil -> None
    | LazyList.Cons (x, _) -> Some (convf x)

let test = function
    | Char System.Char.ToUpper x -> printfn "Matched as %A" x
    | _ -> printfn "Didn't match"

test (LazyList.of_list ['a'])

However, if I change Char from a partial active pattern to a complete active pattern as follows:

let (|Char|NoChar|) convf = function
    | LazyList.Nil -> NoChar
    | LazyList.Cons (x, _) -> Char x

let test = function
    | Char System.Char.ToUpper x -> printfn "Matched as %A" x
    | NoChar System.Char.ToUpper -> printfn "Didn't match"

test (LazyList.of_list ['a'])

Then the code fails to compile, giving the following error message: error FS0191: Only active patterns returning exactly one result may accept arguments.

This example may look somewhat contrived, but it’s a simplified version of an active pattern I tried to use in a Prolog lexer I’ve been working on in my spare time. I can easily rewrite my code to avoid this problem, but I’m curious about why this sort of code is disallowed.

Update: the newer versions of F# seem to have renamed this error:

error FS0722: Only active patterns returning exactly one result may accept arguments

  • 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-12T10:47:10+00:00Added an answer on May 12, 2026 at 10:47 am

    NB. This is exactly what Brian said, but hopefully stated in a clearer fashion.

    I recall logging a bug on precisely this issue and IIRC this is what Don Syme had to say on the matter.

    A multi-case active pattern is a conversion function from some input value into one of several output values. In your example, any character is converted to the Char case or the NoChar case.

    The benefit of this is that the F# compiler calls the multi-case active pattern function once and can then generally determine which pattern match rule to evaluate next.

    If you allow a parameter however, then you need to evaluate the multi-case active pattern for every pattern match rule.

    So imagine the following

    match input with
    | Alpha "foo" -> ...
    | Bravo "bar" -> ...
    

    When evaluating (|Alpha|Bravo|) “foo” returned ‘Bravo’, then the first rule wouldn’t match. Likeways (|Alpha|Bravo|) “bar” returns ‘Alpha’, then the second rule wouldn’t match either. So you don’t really have a multi-case active pattern. Just a paramterized, partial active pattern. (Because for some inputs the expected pattern-case won’t be hit.)

    So when confronted with a corner of the language that doesn’t make a whole lot of sense, and in fact can be made much clearer by the partial, parameterized active pattern. The feature wasn’t added to the language.

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

Sidebar

Related Questions

I'm new to regular expressions. The following code works as expected, printing first true
The following code works as expected on CentOS and Ubuntu O/s but not on
Doing an ajax get request works as expected using the following code: $.ajax({ type:
The following code works as expected in IE8 and Safari4, but not in Firefox3.6
The following piece of code works as expected when running in a local install
I have the following code which works as expected: #include <iostream> using namespace std;
The following code works as expected: NSLog(@%@, [NSString stringWithString:@test]; // Logs test But when
The following code works as expected for me under 64-bits, but fails under 32-bit
I have the following code that works as expected: a = [1, 2, 3,
Working SQL The following code works as expected, returning two columns of data (a

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.