Error using F # Active Pattern

Why is this compiling:

let (|T|F|) b = 
    let f (o:int) : obj = null
    if b then T else F(f)

while this fails:

let (|T|F|) b = 
    let f (o:obj) : obj = null
    if b then T else F(f)

The difference between the two examples is that the argument β€œo” is forced to either β€œint” (compilation) or β€œobj” (cannot compile)

+3
source share
1 answer

This is a sad case of input output. This will work:

let (|T|F|) b : Choice<unit,obj -> obj> =   
  let f (o:obj) : obj = null
  if b then T else F(f)

, (o:obj), F # , o 'a, bool -> Choice<unit,'a -> obj>. 'a , F # . , - :

let (|T|F|) b =   
  if b then T else F []

, :

let (|T|F|) b : Choice<unit,int list>  =   
  if b then T else F []
+8

Source: https://habr.com/ru/post/1767610/


All Articles