Can I selectively open a module so that I can refer to some of its values ​​without qualification?

In Haskell, I use the Data.Map module and its main type with the same Data.Map.Map name, for example:

 import Data.Map (Map) import qualified Data.Map as M 

In F #, I want to do something similar with my Item module, which contains the type of the same name:

 module Item type Item = { Description: string } let empty = { Description = "" } 

I can not find a way to use this module and the type is unqualified. Can I use this module and call it the following:

 let getItem (): Item = Item.empty 

Edit:

Adding a type alias from the client module allows you to use the Item module with qualifications and the Item type without qualifications, but is there an even better way?

 type Item = Item.Item 
+4
source share
1 answer

I think the only way to import only one type from a module is to use a type alias (as you already noted). To get qualified access to the module members (under a different name), you can use the module alias:

 type Item = Item.Item // Type-alias for type(s) from module module I = Item // Module-alias for accessing members // Now you can write: let getItem() : Item = I.empty 

I don’t think there is any way to import participants from the module selectively (as in Haskell), so this is probably the best option.

+9
source

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


All Articles