In Haskell, I use the Data.Map
module, and its principal type of the same name, Data.Map.Map
, like this:
import Data.Map (Map)
import qualified Data.Map as M
In F#, I want to do something similar with my Item
module, which contains a type of the same name:
module Item
type Item = { Description: string }
let empty = { Description = "" }
I can't find a way to use this module qualified and the type unqualified. Can I use this module and type like this, from another module?
let getItem (): Item = Item.empty
Edit:
Adding a type alias from a client module lets me use the Item
module with qualification and the Item
type without qualification, but is there a better way still?
type Item = Item.Item
I think the only way to import only a single type from a module is to use type alias (as you already noted). To get a qualified access to members of the module (under a different name), you can use 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 for importing members from module selectively (as in Haskell), so this is probably the best option.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With