Opened 6 years ago

Closed 3 years ago

#4364 closed bug (fixed)

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@…,…, awson
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case: th/T4364
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:


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 )

    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 (10)

comment:1 Changed 6 years ago by simonpj


We won't do this for 7.0; it's not a regression. It'll be part of the TH improvements described in

comment:2 Changed 6 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.


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

import Data.HList
import Language.Haskell.TH

makeRecord :: [(Name,Name)] -> Q Type
makeRecord lvs =
  [t| Record $(ps) |]
    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)|]


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

import Data.HList.MakeLabels

$(label "size")


{-# 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- ... linking ... done.
Loading package array- ... linking ... done.
Loading package containers- ... 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 )

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

I am using the GHC from here: on Debian testing

comment:3 Changed 6 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 Just gotta do it. But several other things are queued up first, alas.


comment:4 Changed 5 years ago by PHO

Cc: pho@… added

comment:5 Changed 5 years ago by simonpj

difficulty: Unknown

No time to do this before 7.4. Sorry

comment:6 Changed 4 years ago by igloo


comment:7 Changed 4 years ago by liyang

Cc:… added

comment:8 Changed 4 years ago by awson

Cc: awson added

comment:9 Changed 3 years ago by Krzysztof Gogolewski <krz.gogolewski@…>

In e595c81ee0951f17d34b918123dfa7711710fe89/testsuite:

Add tests for new TH #4124, #4128, #4170, #4364, #6062

comment:10 Changed 3 years ago by monoidal

Resolution: fixed
Status: newclosed
Test Case: th/T4364

This is now fixed thanks to new TH. Woo hoo!

Note: See TracTickets for help on using tickets.