Opened 4 years ago

Closed 6 months 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@…, hackage.haskell.org@…, awson
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Difficulty: Unknown
Test Case: th/T4364 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 (10)

comment:1 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

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

comment:3 Changed 3 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

comment:4 Changed 2 years ago by PHO

  • Cc pho@… added

comment:5 Changed 2 years 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

comment:6 Changed 19 months ago by igloo

  • Milestone changed from 7.6.1 to 7.8.1

comment:7 Changed 13 months ago by liyang

  • Cc hackage.haskell.org@… added

comment:8 Changed 13 months ago by awson

  • Cc awson added

comment:9 Changed 6 months ago by Krzysztof Gogolewski <krz.gogolewski@…>

In e595c81ee0951f17d34b918123dfa7711710fe89/testsuite:

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

comment:10 Changed 6 months ago by monoidal

  • Resolution set to fixed
  • Status changed from new to closed
  • Test Case set to th/T4364

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

Note: See TracTickets for help on using tickets.