Import a type family that is an operator in Haskell
Asked Answered
P

1

5

GHC.TypeNats exports type family of the following signature:

type family (m :: Nat) + (n :: Nat) :: Nat 

How can I import it explicitly? import GHC.TypeNats((+)) does not work, because it says that GHC.TypeNats does not export (+)...

Everything compiles okay when I import whole module implicitly, but this really is not what I want to have in my code.


I am using GHC 8.6.5

Phlegm answered 25/10, 2019 at 20:44 Comment(0)
S
9

From the manual:

There is now some potential ambiguity in import and export lists; for example if you write import M( (+) ) do you mean the function (+) or the type constructor (+)? The default is the former, but with ExplicitNamespaces (which is implied by TypeOperators) GHC allows you to specify the latter by preceding it with the keyword type, thus:

import M( type (+) )
Shahaptian answered 25/10, 2019 at 20:57 Comment(2)
How do you import (*) though? That is a parse error in GHC 9.0 it seems.Anthroposophy
@Anthroposophy you have to set {-# LANGUAGE NoStarIsType #-} It took me a while to realizeCodfish

© 2022 - 2024 — McMap. All rights reserved.