Skip to content

Brackets and splices should be overloaded like the static keyword

It's quite convenient that the static keyword is rebindable. To recap, if e :: T then static e :: (IsStatic p) => p t.

It should also be possible rebind brackets and splices in the same manner. So we introduce two type classes IsBracket and IsSplice. Now quoting a term e :: T has type e :: IsBracket p => p T and the argument to a splice must have type e :: IsSplice p => p T which results in a value of type T.

class IsBracket p where
  fromBracket :: Code t -> p t

class IsSplice p where
  toBracket :: p t -> Code t

foo :: IsBracket p => p Int
foo = [|| 5 ||]

qux :: (IsSplice p, IsBracket p) => Int
qux = $$(foo)

As an aside, arguably the static form should only be rebindable when RebindableSyntax is enabled but that boat seems to have sailed.

Trac metadata
Trac field Value
Version 8.6.3
Type FeatureRequest
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Template Haskell
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information