What is the RequireQualifiedAccess attribute?

From docs :

This attribute is used to indicate that references to elements of a module, record, or join type require explicit qualified access.

What is explicit qualified access? What is implicit access?

+4
source share
3 answers

The behavior of manual F # list operators, arrays, and sequences is mirrored between modules so that you can work with these structures sequentially. The implementations are different.

if you prefer to work in an implicit style, it's easy to set this up. For example, if you work primarily with lists, you can do this:

let inline map = List.map

etc.

, (.. , , , List.map). , . ? . , ? , RequireQualifiedAccess. - , . ? ?

, , . ( DicriminatedUnion.Case1):

type DiscinatedUnion = 
  | Case1
  | Case2
  | Case3

let f x =
  match x with
  | Case1 -> "case1"
  | Case2 -> "case2"
  | Case3 -> "case3"

f Case1

F #

, Haskell, , . F #, F # , , . , .

+4

F #

[<RequireQualifiedAccess>] , . , Microsoft.FSharp.Collections.List .

, , , : .

+4

Perhaps a concrete example will help.

The module Listhas this attribute. This means that you are not allowed to open the module:

open List // compile error!

map id [1;2]

Instead, you should do this:

List.map id [1;2]
+4
source

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


All Articles