How can I make this match expression more concise?

dudeNumber4

Learning F# by writing blackjack. I have these types:

type Suit = 
| Heart = 0
| Spade = 1
| Diamond = 2
| Club = 3

type Card =
| Ace of Suit
| King of Suit
| Queen of Suit
| Jack of Suit
| ValueCard of int * Suit

I have this function (ignoring for now that aces can have 2 different values):

let NumericValue =
  function | Ace(Suit.Heart) | Ace(Suit.Spade) | Ace(Suit.Diamond) | Ace(Suit.Club) -> 11
         | King(Suit.Heart) | King(Suit.Spade)| King(Suit.Diamond) | King(Suit.Club) | Queen(Suit.Heart) | Queen(Suit.Spade)| Queen(Suit.Diamond) | Queen(Suit.Club) | Jack(Suit.Heart) | Jack(Suit.Spade)| Jack(Suit.Diamond) | Jack(Suit.Club) -> 10
         | ValueCard(num, x) -> num

Is there a way I can include a range or something? Like [Ace(Suit.Heart) .. Ace(Suit.Club)]. Or even better Ace(*)

kaefer

You want a wildcard pattern. The spec (§7.4) says:

The pattern _ is a wildcard pattern and matches any input.

let numericValue = function 
| Ace _-> 11
| King _
| Queen _
| Jack _ -> 10
| ValueCard(num, _) -> num

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How can I make this method more concise?

From Dev

How can I make a for-loop pyramid more concise in Python?

From Dev

How can I refactor this code to be more concise?

From Dev

Can I make this if statement with lots of ORs more concise?

From Dev

How can I make a regular expression move to the next match?

From Dev

Parsing: how can I generate a more concise AST?

From Dev

how can I build this method in a more concise way?

From Dev

If/yield cascade - how to make more concise?

From Dev

If/yield cascade - how to make more concise?

From Dev

How can I be more specific with this regular expression?

From Dev

How can I match regular expression for this url?

From Dev

How can I match regular expression for this url?

From Dev

How can I repeat a match in a regular expression?

From Dev

How can I swap this JavaScript nested For Loop for something more clear and concise?

From Dev

How can I make this Observable more reusable?

From Dev

How can I make this loop more efficient?

From Dev

How can I make this Makefile more generic?

From Dev

How can I make the button more visible?

From Dev

How can I make this loop more efficient?

From Dev

How can I make this code more elegant?

From Dev

How can I make a Read More Button?

From Dev

A more concise version of this Regular Expression?

From Dev

How can I make this cases match with regex?

From Dev

How can I match zero or more instances of a pattern in bash?

From Dev

How can I match parameters in command line with one regular expression?

From Dev

How can I get the last match in regular extracor expression in jmeter?

From Dev

How can I use TryParse in a guard expression in match?

From Dev

How can I make this PHP/MySQL game map more efficient?

From Dev

How can I make this recursive function more efficient?

Related Related

  1. 1

    How can I make this method more concise?

  2. 2

    How can I make a for-loop pyramid more concise in Python?

  3. 3

    How can I refactor this code to be more concise?

  4. 4

    Can I make this if statement with lots of ORs more concise?

  5. 5

    How can I make a regular expression move to the next match?

  6. 6

    Parsing: how can I generate a more concise AST?

  7. 7

    how can I build this method in a more concise way?

  8. 8

    If/yield cascade - how to make more concise?

  9. 9

    If/yield cascade - how to make more concise?

  10. 10

    How can I be more specific with this regular expression?

  11. 11

    How can I match regular expression for this url?

  12. 12

    How can I match regular expression for this url?

  13. 13

    How can I repeat a match in a regular expression?

  14. 14

    How can I swap this JavaScript nested For Loop for something more clear and concise?

  15. 15

    How can I make this Observable more reusable?

  16. 16

    How can I make this loop more efficient?

  17. 17

    How can I make this Makefile more generic?

  18. 18

    How can I make the button more visible?

  19. 19

    How can I make this loop more efficient?

  20. 20

    How can I make this code more elegant?

  21. 21

    How can I make a Read More Button?

  22. 22

    A more concise version of this Regular Expression?

  23. 23

    How can I make this cases match with regex?

  24. 24

    How can I match zero or more instances of a pattern in bash?

  25. 25

    How can I match parameters in command line with one regular expression?

  26. 26

    How can I get the last match in regular extracor expression in jmeter?

  27. 27

    How can I use TryParse in a guard expression in match?

  28. 28

    How can I make this PHP/MySQL game map more efficient?

  29. 29

    How can I make this recursive function more efficient?

HotTag

Archive