Declaring Inner Types in F #

I recently came across a list of codes:

type MyType = | MyType of int and internal MyInternal = | One of MyType | Two of MyType 

I am not familiar with the use of "and internal" (on the third line), and I was wondering if there is any difference between using "type internal" as follows:

 type MyType = | MyType of int type internal MyInternal = | One of MyType | Two of MyType 

I experimented briefly with both forms, and I see no difference. Are these just two different ways to write the same thing?

+6
source share
2 answers

In this case, the and keyword will be used to define mutative-recursive types MyType and MyInternal . Since MyType and MyInternal are not mutually recursive, and not required.

As indicated on the MSDN page:

Keyword and keyword replaces all keywords except the first definition

therefore, the definitions are equivalent.

+5
source

No, your suggested code is definitely more idiomatic.

 type T = ... and U = ... 

usually used only if the types are mutually recursive. Using it with an internal type would be even stranger, since the constructors of the first type must also be made internal:

 type T = internal | T of U and internal U = | U of T 
+3
source

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


All Articles