haskell-suite / haskell-src-exts

Manipulating Haskell source: abstract syntax, lexer, parser, and pretty-printer
Other
193 stars 94 forks source link

Adding a "type" prefix when printing type operator import specs with import lists #475

Open viktorcsimma opened 1 year ago

viktorcsimma commented 1 year ago

When importing type operators, GHC expects the ExplicitNamespaces pragma (which TypeOperators implies) and the type prefix before the import spec.

But this did not happen when the ImportSpec was given with the constructor IThingWith or IThingAll since they do not contain namespaces. I've changed the Pretty instance so that they get this prefix if the parent is an operator.

An example:

{-# LANGUAGE TypeOperators #-}

module TypeOperatorImport where

import TypeOperatorExport ((&&&), type (***)((:*:)), type (<))

test1 :: (<) () Bool
test1 = ()

test2 :: Bool -> Bool -> (***) () Bool
test2 b1 b2 = () :*: (b1 &&& b2)

I've tried to create tests for this, but I got Parse error messages for the ((:*:)) part.

Thank you in advance:)