Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

haskell hide import of star-operator

Tags:

haskell

I have:

import qualified GHC.Types as T hiding (Module, (*))
import GHC.TypeNats hiding ((*))

but when I try to define a (*)-operator, it fails:

{-# INLINE (*) #-}
infixl 7 *
(*) :: r -> r -> r
(*) = undefined

with

error:
    Ambiguous occurrence ‘*’
    It could refer to either ‘T.*’,
                             imported qualified from ‘GHC.Types’ at ...
                          or ‘*’,
                             imported from ‘GHC.TypeNats’ at ...
     |
1277 |     infixl 7 *

EDIT: the description is currently not reproducible. I will update the question as soon as I can.

like image 808
Leander Avatar asked Jun 07 '18 21:06

Leander


1 Answers

Neither GHC.Types nor GHC.TypeNats have a (*) export. They both have a type (*) export. Usually, you can distinguish between term-level (*) and type-level (*) by context, but this is not true in export/import lists. Instead, term-level is taken as default, and you must explicitly say you want to hide the types.

import qualified GHC.Types as T hiding (Module, type (*))
import GHC.TypeNats hiding (type (*))

The reason Module remains unadorned is because the capitalization means it must be either a type, a constructor, or a pattern synonym. Constructors must occur inside grouping () next to their data types, and pattern synonyms must be set apart with pattern, so the Module above is taken to refer to the data type (hiding the data type also hides all of its constructors).

The reason you did not get an error when you tried to hide something that didn't exist is because hiding was designed so that, if the imported module ever stopped exporting something you hid, your module would not fail to compile. After all, the only reason you referenced that thing was to say that you weren't going to reference that thing.

like image 190
HTNW Avatar answered Oct 31 '22 17:10

HTNW