convention around pattern synonyms

Viktor Dukhovni ietf-dane at dukhovni.org
Wed Dec 29 23:12:13 UTC 2021


Some "GHC-internal" types leak to users via TH, and their constructors
occasionally pick up new fields, causing breakage downstream.  The extra
field often has a sensible default (Nothing, [], ...) and it should be
best practice to rename the constructor when adding the new field, while
replacing the original constructor with a pattern synonym with the "old"
signature.

	data Foo = ...
		 | NewImprovedMkFoo X Y Z -- was MkFoo Y Z

	pattern MkFoo :: Foo
	pattern MkFoo Y Z = NewImprovedMkFoo Nothing Y Z

When pattern synonyms are used to maintain a backwards-compatible API,
there should of course be no special signalling to differentiate them
from "real" constructors.

The boundary between "GHC-internal" and external may not always be
obvious, some care is required to reduce leaking breakage via TH.

-- 
	Viktor.


More information about the ghc-devs mailing list