después de algún juego en torno F cuentan con limitaciones # miembros y función de escritura de la siguiente manera:F limitaciones # miembros +^a byref parámetros
let inline parse< ^a when ^a : (static member Parse: string -> ^a) > s =
(^a: (static member Parse: string -> ^a) s)
que funciona perfectamente bien:
let xs = [ "123"; "456"; "999" ] |> List.map parse<int>
Estoy intentando escribir other func tryParse
, que usa el método estático TryParse
y envuelve el resultado del análisis en el tipo 'a option
para un mejor soporte en F #. Algo como esto no se compila:
let inline tryParse s =
let mutable x = Unchecked.defaultof< ^a>
if (^a: (static member TryParse: string * ^a byref -> bool) (s, &x))
then Some x else None
El error es: FS0001
de error: Esta expresión se espera que tenga tipo byref < 'a> pero aquí tiene tipo 'a ref
F # ref
-células d oesn't work too:
let inline tryParse s =
let x = ref Unchecked.defaultof< ^a>
if (^a: (static member TryParse: string * ^a byref -> bool) (s, x))
then Some x else None
¿Qué estoy haciendo mal?
Ay, creo esto es un error ... también, 'TryParse: string -> bool *^a' no funciona. –
Esto parece estar arreglado en F # 3.0. – kvb