Opened 6 months ago

Last modified 6 months ago

#8460 patch feature request

Annotation reification with types in TH

Reported by: errge Owned by:
Priority: normal Milestone: 7.10.1
Component: Template Haskell Version: 7.7
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Difficulty: Easy (less than 1 hour)
Test Case: Blocked By:
Blocking: Related Tickets: #8397


The attached patch adds two simple helper functions to support typed reification of annotations. This was not in the original #8397 patch only because the typed branch was not merged at that time.

Attachments (1)

th-ann-typed.patch (1.6 KB) - added by errge 6 months ago.

Download all attachments as: .zip

Change History (6)

Changed 6 months ago by errge

comment:1 Changed 6 months ago by errge

  • Status changed from new to patch

comment:2 Changed 6 months ago by errge

  • Component changed from Compiler to Template Haskell

comment:3 Changed 6 months ago by errge

  • Milestone changed from 7.8.1 to 7.10.1

comment:4 Changed 6 months ago by monoidal

I like liftTyped. I would go even further and add it to the Lift class:

class Lift t where
  lift :: t -> Q Exp
  liftTyped :: t -> Q (TExp t)
  lift = unTypeQ . liftTyped
  liftTyped = unsafeTExpCoerce . lift
  {-# MINIMAL lift | liftTyped #-}

Now, when you write an instance of Lift

data A = A

instance Lift A where
  liftTyped A = [e|| A ||]

the compiler will detect if you mistakenly use a different type in the [e|| ... ||] brackets.

comment:5 Changed 6 months ago by errge

Fine with me if it gets merged it like that, thanks for the idea!

Note: See TracTickets for help on using tickets.