Ticket #4364 (new bug)

Opened 3 years ago

Last modified 3 months ago

Template Haskell: Cycle in type synonym declarations

Reported by: igloo Owned by: simonpj
Priority: high Milestone: 7.8.1
Component: Compiler (Type checker) Version: 7.1
Keywords: Cc: jakewheatmail@…, pho@…, hackage.haskell.org@…, awson
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Difficulty: Unknown
Test Case: Blocked By:
Blocking: Related Tickets:

Description

type-level-numbers-0.1 doesn't build with 7.0.1 RC 1. Here's the essence:

{-# LANGUAGE TemplateHaskell #-}
module Q where

data Z

type N0 = $( [t| Z |] )
type N1 = $( [t| Z |] )
$ ghc --make m.hs
[1 of 1] Compiling Q                ( m.hs, m.o )

m.hs:7:1:
    Cycle in type synonym declarations:
      m.hs:7:1-23: type N0 = $([t| Z |])
      m.hs:8:1-23: type N1 = $([t| Z |])

Change History

Changed 3 years ago by simonpj

  • milestone changed from 7.0.1 to 7.2.1

We won't do this for 7.0; it's not a regression. It'll be part of the TH improvements described in  http://hackage.haskell.org/trac/ghc/blog/Template%20Haskell%20Proposal

Changed 2 years ago by jakewheat

  • cc jakewheatmail@… added

Hello, I am getting the same error with the following code. This code compiles fine in ghc 6.12.1 - I'm not sure if this is the same bug or not.

ThStuff?.hs:

{-# LANGUAGE TemplateHaskell #-}
module ThStuff (makeRecord) where

import Data.HList
import Language.Haskell.TH

makeRecord :: [(Name,Name)] -> Q Type
makeRecord lvs =
  [t| Record $(ps) |]
  where
    ps = sequence (map mkPair lvs) >>= foldIt
    mkPair (l,v) = [t| LVPair (Proxy $(conT l)) $(conT v) |]

foldIt :: [Type] -> Q Type
foldIt = \tt -> case tt of
                  [] -> [t|HNil|]
                  (t:ts) -> [t| HCons $(return t) $(foldIt ts)|]

Types.hs:

{-# LANGUAGE TemplateHaskell,EmptyDataDecls,DeriveDataTypeable,FlexibleContexts #-}
module Types where

import Data.HList.MakeLabels

$(label "size")

Test.hs:

{-# LANGUAGE TemplateHaskell #-}
import Data.HList
import ThStuff
import Data.HList.Label4 ()
import Types

-- this definition only works in ghc 6.12.1

type TestRow = $(makeRecord [(''Size, ''Int)])

-- using this definition works in both ghc 6.12.1 and ghc 7.0.2

--type TestRow = Record (HCons (LVPair (Proxy Size) Int)
--                             HNil)

main :: IO ()
main = do
  let t :: TestRow
      t = size .=. 1
          .*. emptyRecord
  print t

$ ghc --version
The Glorious Glasgow Haskell Compilation System, version 7.0.2
$ ghc --make Test.hs
[1 of 3] Compiling Types            ( Types.hs, Types.o )
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Loading package ffi-1.0 ... linking ... done.
Loading package pretty-1.0.1.2 ... linking ... done.
Loading package array-0.3.0.2 ... linking ... done.
Loading package containers-0.4.0.0 ... linking ... done.
Loading package template-haskell ... linking ... done.
Loading package HList-0.2.3 ... linking ... done.
[2 of 3] Compiling ThStuff          ( ThStuff.hs, ThStuff.o )
[3 of 3] Compiling Main             ( Test.hs, Test.o )

Test.hs:10:1:
    Cycle in type synonym declarations:
      Test.hs:10:1-46: type TestRow = $(makeRecord [('Size, 'Int)])

I am using the GHC from here:  http://haskell.org/ghc/download_ghc_7_0_2#x86_64linux on Debian testing

Changed 2 years ago by simonpj

Yes, same problem. The trouble is that type splices currently throw up their hands and conservatively say "I might refer to any other type". Solution is  http://hackage.haskell.org/trac/ghc/blog/Template%20Haskell%20Proposal. Just gotta do it. But several other things are queued up first, alas.

Simon

Changed 18 months ago by PHO

  • cc pho@… added

Changed 18 months ago by simonpj

  • difficulty set to Unknown
  • milestone changed from 7.4.1 to 7.6.1

No time to do this before 7.4. Sorry

Changed 9 months ago by igloo

  • milestone changed from 7.6.1 to 7.8.1

Changed 3 months ago by liyang

  • cc hackage.haskell.org@… added

Changed 3 months ago by awson

  • cc awson added
Note: See TracTickets for help on using tickets.