F #: suppression of discriminatory union

I have a discriminated union type:

type F =
| A of int
| B of float

Suppose I have a list F that has been filtered to get only objects of type A:

let listOfAs=list.filter (fun f -> match f with | A(f') -> true | _ -> false)

How can I work with the resulting list F without requiring pattern matches in all my code? The compiler does not like live broadcasting, for example

list.map (fun f -> int f) listOfAs
+4
source share
1 answer

You cannot distinguish between the disqualified value of union - a type Fis something other than a type int(this is not like a C-connection, where they have the same binary representation).

, , list<F> list<int>, int, A.

List.choose ( List.filter). , None ( ) Some v ( v ):

let listOfAs = List.choose (fun f -> 
  match f with 
  | A(f') -> Some f'
  | _ -> None)
+8

All Articles