This question has a subtle answer "no, but yes", which requires a transition to three concepts:
- Qualified Names vs. Unqualified Names
- Modules and Import
- Distortions
Point 1: each definition in Haskell has both a short, unqualified name of type map , and a long, qualified name of type Data.List.map .
Point 2: when importing a module into another, you can perform qualified or unskilled import. When you use unqualified imports, the names of the external modules you enter will be aliases under their short names. When you perform qualified import, they will be available only under the changed name:
import qualified Data.Map as Map
Now in the module where it appeared, the Data.Map.map function is visible under the alias Data.map .
Third point: this means that every Haskell definition has a fully qualified name defined by its short name and the module where it is defined, as well as unqualified or partially qualified aliases in each module where it is imported.
Now your question has two answers:
- Two different classes cannot have methods that have the same fully qualified name. Therefore, if you define your
Foo and Bar classes in the same module, this will not work. - Two different classes may have methods that have the same unqualified name if their fully qualified names are different, i.e. they are defined in different modules. However, for use as inside one client module, you will need at least one qualified import so that aliases from the import do not collide.
source share