A way to make sure that our functions use abbreviated types instead of primitives in F #, except to always write yourself?

Let's say I defined an abbreviation like

type Individual = Double array

and that I use it in the whole F # project:

let generateIndividual = [|1.0; 2.0|]

IntelliSense tells me that it generateIndividualhas an associated return type float[]. Since I would prefer it to display Individualas a return type, I change my signature to

let generateIndividual : Individual = [|1.0; 2.0|]

When using the internal code, it really does not matter what Intellisense is. But when using the API for the outside world, it seems more attractive that my functions display aliases rather than primitive types.

Is there any way to avoid having to enter them other than as described above? At Swensen’s suggestion, I looked at the signature files, and although at first they turned out to be exactly what I was looking for, they seem to be unable to do this.

+5
source share
1 answer

Individual F #, ( ) . (, Double array). , F # , , . , - , .

, . - , :

type Individual = Individual of Double array

// Creating single-case union
let generateIndividual = Individual [|1.0; 2.0|]  

// Decomposing single-case union
let sumIndividual (Individual data) = Array.sum data
+5

All Articles