F # how to expand the general type of an array?

Following this question I wonder how (or if) I can extend the general type of an F # array. I could do this:

type System.Array with member a.Last = a.GetValue(a.Length - 1) 

but, as Thomas said, he is not general. Then I tried this, but it does not work:

 type Microsoft.FSharp.Collections.Array with // Error: Array is not defined member a.Last = a.[a.Length - 1] 

In F # scource, I found this namespace, but it doesn't work either:

 type Microsoft.FSharp.Primitives.Basics.Array with // Error: Array is not defined member a.Last = a.[a.Length - 1] 
+6
source share
1 answer

This is a bit confusing - but I recently searched for something in the F # spec and came across this:

 type 'T ``[]`` with member a.Last = a.[a.Length - 1] [| 1 .. 10 |].Last 

Double countdown coding is usually used to include reserved keywords in valid F # identifiers (for example, if you want to have a property that has a space in the name or is called let ). Here, probably, this means that the compiler should treat [] as a regular type of "name", and not as a special syntax for arrays.

+16
source

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


All Articles