Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to nest calls to F# active patterns?

Tags:

f#

Is there a way to nest calls to active patterns?

Something like this:

type Fnord =
| Foo of int

let (|IsThree|IsNotThree|) x = 
  match x with
  | x when x = 3 -> IsThree
  | _ -> IsNotThree

let q n =
  match n with
  | Foo x ->
    match x with
    | IsThree -> true
    | IsNotThree -> false
  // Is there a more ideomatic way to write the previous
  // 5 lines?  Something like:
//  match n with
//  | IsThree(Foo x) -> true
//  | IsNotThree(Foo x) -> false

let r = q (Foo 3) // want this to be false
let s = q (Foo 4) // want this to be true

Or is the match followed by another match the preferred way to go?

like image 712
James Moore Avatar asked Jan 04 '10 01:01

James Moore


People also ask

Can Google Nest call phone numbers?

Google-supported calling allows you to make audio calls to mobile, landline, and business phone numbers at no additional cost. Important: As of mid-December 2020, if you're in the UK, you're no longer able to make Google-supported calls on your speaker or display. You can still make audio or video calls through Duo.

What is a Nest call?

With carrier calling on speakers and displays, you can use your phone's mobile or landline service plan to call friends, family, and businesses as your plan allows. Calls you make are billed according to your plan.

Can Google nests communicate?

Send a message to everyone in your home with the broadcast feature on Google Home and Nest speakers and displays.

How do I make calls from Google Nest?

Google-supported calls: This is the simplest way to make voice calls on your Google Nest devices. Simply say, "Hey, Google, call [name in your Google Contacts]." You can make free calls to US and Canadian mobile, landline and business phone numbers.


1 Answers

It works. You just have the patterns backwards.

type Fnord =
| Foo of int

let (|IsThree|IsNotThree|) x = 
  match x with
  | x when x = 3 -> IsThree
  | _ -> IsNotThree

let q n =
  match n with
  | Foo (IsThree x) -> true
  | Foo (IsNotThree x) -> false

let r = q (Foo 3) // want this to be true
let s = q (Foo 4) // want this to be false
like image 85
gradbot Avatar answered Sep 29 '22 07:09

gradbot