Skip to content

Allow pattern synonyms to be bundled with type classes?

One can very nearly get associated pattern synonyms by defining suitably polymorphic pattern synonyms. However, they are not quite associated as there's no way to bundle them with the class. This isn't as good as "proper" support but it would be an easy thing to implement for now if people think it worthwhile.

For a concrete example, Null is an associated pattern synonym in this style but the following program doesn't compile because it is disallowed to bundle a pattern synonym with a type class.

{-# LANGUAGE PatternSynonyms #-}

module Foo(Nullable(Null)) where

import Data.Maybe

class Nullable f where
  null :: f a -> Bool

instance Nullable (Maybe a) where
  null = isNothing

pattern Null :: Nullable f => f a
pattern Null = (null -> True)
Edited by Herbert Valerio Riedel
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information