Why is the `DA.Date` module imported qualified?

I can see in some Daml code that the DA.Date module is imported qualified like this:

import DA.Date qualified as D

after which the functions from the module are used like this:

dateOfBirth = D.date 2021 D.Aug 12

I cannot see the point of this, what am I missing?

There are two main reasons for qualified imports in general:

  1. To avoid collisions between functions with the same name.
  2. Readability: It makes it a lot easier to see where a function was imported from without having to rely on editor tooling or guessing which can be helpful in particular for readers that are not that familiar with a library. This is obviously highly subjective as most readability questions

I don’t know where you got your example from but having two functions called date seems fairly unlikely so it’s probably because of 2.

1 Like

I find myself often in the situation that a template field called date conflicts with the import. This is usually the reason I have to qualify it.

2 Likes