Skip to content

:info for record pattern synonyms

At present, when :info is used for a pattern synonym field selector, GHCi prints the type of the selector function. For example:

GHCi, version 9.1.20210216: https://www.haskell.org/ghc/  :? for help
ghci> :set -XPatternSynonyms
ghci> pattern P{x,y} = (x,y)
ghci> :info x
x :: (a,b) -> a 	-- Defined at <interactive>:2:11

However, this doesn't make sense if the pattern synonym was defined when NoFieldSelectors was enabled, because no such function exists. (At the moment I think HEAD will show some nonsense like $sel:x:P :: (), but I don't have a build available to test right now.) What should it show instead?

Using :info on the pattern synonym itself shows the type of the builder (without field names).

ghci> :info P
pattern P :: a -> b -> (a, b) 	-- Defined at <interactive>:2:1

For comparison, using :info on a normal field selector shows a condensed version of the datatype to which it belongs, which is more informative and makes sense even when NoFieldSelectors is in use:

ghci> data Pair a b = MkPair { x :: a, y :: b }
ghci> :info x
type Pair :: * -> * -> *
data Pair a b = MkPair {x :: a, ...}
  	-- Defined at <interactive>:4:26
ghci> :info Pair
type Pair :: * -> * -> *
data Pair a b = MkPair {x :: a, y :: b}
  	-- Defined at <interactive>:4:1
ghci> :info MkPair
type Pair :: * -> * -> *
data Pair a b = MkPair {...}
  	-- Defined at <interactive>:4:17

(In the last case it seems odd to elide the fields of MkPair, but it isn't really a problem.)

Perhaps we should do something similar in the pattern synonym case, and show the full definition? That is, :info on a pattern synonym or one of its fields could yield something like:

pattern P :: a -> b -> (a, b)
pattern P{x,y} = (x,y)

This would convey more information and be valid even when NoFieldSelectors is in use.

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information