Preventing import of `DA.Internal`

Continuing the discussion from How to qualify names in export list?:

Following @bernhard 's suggestion, I have used {-# LANGAUGE NoImplicitPrelude #-} to try and hide some standard functions; however, I’m still getting errors such as:

/home/luciano/src/da-marketplace/contingent-claims/daml/ContingentClaims/Valuation.daml|26 col 25| typecheck:Error:/home/luciano/src/da-marketplace/contingent-claims/daml/ContingentClaims/Valuation.daml:26:25: error: Ambiguous occurrence ‘negate’ It could refer to either ‘DA.Internal.RebindableSyntax.negate’, imported from ‘DA.Internal.RebindableSyntax’ (and originally defined in ‘GHC.Num’) or ‘ContingentClaims.Math.Ring.negate’, imported from ‘ContingentClaims.Math.Ring’ at /home/luciano/src/da-marketplace/contingent-claims/daml/ContingentClaims/Valuation.daml:7:1-33 (and originally defined at /home/luciano/src/da-marketplace/contingent-claims/daml/ContingentClaims/Math/Ring.daml:21:1-6)

Is this a bug?

Looking at the source code, I can see that Prelude re-exports some of these DA.Internal functions.
What confuses me is that it’s impossible to explicitly import DA.Internal (it throws an error saying this is not allowed), so I’m baffled why these are even in scope.

1 Like

The Daml compiler inserts 3 imports automatically which are used for desugaring of templates, records and some other stuff. Those imports are

  1. import qualified GHC.Types
  2. import qualified DA.Internal.Desugar
  3. import DA.Internal.RebindableSyntax

The latter is what makes some Haskell syntax contracts (e.g. string literals) work in Daml. There isn’t really any way to disable that import since it is crucial to Daml working as intended.

I think it’s also worth pointing out that all of this is an implementation detail and not something you can rely on.

1 Like

Is there any other way I can overload the pure operator?

This is something that’s been nagging me for ages now, and it would simplify my code considerably.

What’s stopping you from using another name than pure?

Nothing; the meaning of pure here is that of an Applicative; that’s why I want to use this term. But there’s no corresponding <*> operator, so I can’t implement a typeclass instance.

In Haskell, point is commonly used for things that can implement something like pure but no (<*>)