Ticket #3177 (closed feature request: fixed)

Opened 4 years ago

Last modified 4 years ago

support quasiquoting for types

Reported by: claus Owned by:
Priority: normal Milestone: 6.12 branch
Component: Compiler Version: 6.11
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Difficulty: Unknown
Test Case: th/T3177, T3177a Blocked By:
Blocking: Related Tickets:

Description

Currently, quasiquotes are limited to patterns and expressions, though patterns and expressions with explicit type signatures can be generated (with appropriate language flag for pattern signatures).

Since so much of Haskell programming happens at the type level, it would be great if quasiquoting wasn't excluded from that part of the game (think type-level numbers, for instance, or any type-level library that requires constants translated into types).

For just one example, see  http://www.haskell.org/pipermail/haskell-cafe/2009-April/059819.html , where I would like to be able to specify label types and type tags directly at the type-level as well.

related: #1476 (Template Haskell won't address this in the near future, so having quasiquotes for types would narrow the gap)

Change History

follow-up: ↓ 2   Changed 4 years ago by igloo

  • difficulty set to Unknown
  • milestone set to 6.12 branch

Quasi quotes as in the QuasiQuotes? extension, not TemplateHaskell (which already has them), I assume.

in reply to: ↑ 1   Changed 4 years ago by claus

Replying to igloo:

Quasi quotes as in the QuasiQuotes? extension,

Yes. The example uses TH-generation of type synonyms as a (partial) workaround - what is needed instead is the ability to say things like

instance HasField () label [$l| TFalse |]

label = [$l| myLabel |] :: [$l| myLabel |]

not TemplateHaskell (which already has them), I assume.

Whatever makes you think so? See the related ticket I linked to (reported by someone you might know?-).

The TH documentation is rather confusing there, as 7.9.1 first describes the syntax for type quotations, and only later states that type splices aren't implemented.. (unless #1476 has been fixed without closing, the documentation should probably point to it)

  Changed 4 years ago by igloo

Right, with TH you can quasi-quote types (e.g. [t| Int |]), but can't splice them in.

  Changed 4 years ago by simonpj

OK I've implemented type splices for Template Haskell:

Wed May 27 19:12:42 BST 2009  simonpj@microsoft.com
  * Template Haskell: allow type splices
  
  At last!  Trac #1476 and #3177
  
  This patch extends Template Haskell by allowing splices in
  types.  For example
  
    f :: Int -> $(burble 3)
  
  A type splice should work anywhere a type is expected.  This feature
  has been long requested, and quite a while ago I'd re-engineered the
  type checker to make it easier, but had never got around to finishing
  the job.  With luck, this does it.
  
  There's a ToDo in the HsSpliceTy case of RnTypes.rnHsType, where I
  am not dealing properly with the used variables; but that's awaiting
  the refactoring of the way we report unused names.

Give it a try.

Does that allow us to close this ticket? I have not changed the Mainland quasi-quoting stuff at all.

Simon

  Changed 4 years ago by simonpj

  • status changed from new to closed
  • testcase set to th/T3177, T3177a
  • resolution set to fixed

OK, I've added a couple of tests and am closing.

Simon

Note: See TracTickets for help on using tickets.