{-# Language RankNTypes, TypeInType, EmptyCase, GADTs, FlexibleInstances, ConstraintKinds, UndecidableInstances, AllowAmbiguousTypes, InstanceSigs, ScopedTypeVariables #-}importData.KindimportData.ProxytypeCatob=ob->ob->TypedataStruct::(k->Constraint)->TypewhereS::Proxy(a::k)->Struct(cls::k->Constraint)typeStructuredacls=(S('Proxy::Proxya)::Structcls)dataAStruct::Structcls->TypewhereAStruct::clsa=>AStruct(Structuredacls)classStructI(structured::Struct(cls::k->Constraint))wherestruct::AStructstructuredinstance(Structuredxxcls~structured,clsxx)=>StructIstructuredwherestruct::AStruct(Structuredxxcls)struct=AStructdataHom::Catk->Cat(Structcls)whereclassCategory(cat::Catob)wherei::StructIa=>ríkiaainstanceCategoryríki=>Category(Homríki::Cat(Structcls))where-- Commenting out this instance signature makes the issue go awayi::foralla.StructIa=>Homríkiaai=casestruct::AStruct(Structuredacls)of
Running on 8.2.1 and 8.5.20180105 both loop until interrupted
$ ghci -ignore-dot-ghci 199.hsGHCi, version 8.5.20180105: http://www.haskell.org/ghc/ :? for help[1 of 1] Compiling Main ( 199.hs, interpreted )^CInterrupted.> >
Edited
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Child items
...
Show closed items
Linked items
0
Link issues together to show that they're related or that one is blocking others.
Learn more.
I can't reproduce this with either version of GHC you give:
$ /opt/ghc/8.2.2/bin/ghci Bug.hsGHCi, version 8.2.2: http://www.haskell.org/ghc/ :? for helpLoaded GHCi configuration from /home/rgscott/.ghci[1 of 1] Compiling Main ( Bug.hs, interpreted )Bug.hs:29:8: error: • Couldn't match type ‘ríki1’ with ‘Hom ríki’ ‘ríki1’ is a rigid type variable bound by the type signature for: i :: forall k2 (cls1 :: k2 -> Constraint) (a :: Struct cls1) (ríki1 :: Struct cls1 -> Struct cls1 -> *). StructI a => ríki1 a a at Bug.hs:29:8-42 Expected type: ríki1 a a Actual type: Hom ríki a a • When checking that instance signature for ‘i’ is more general than its signature in the class Instance sig: forall (a :: Struct cls0). StructI a => Hom ríki a a Class sig: forall k (cls :: k -> Constraint) (a :: Struct cls) (ríki :: Struct cls -> Struct cls -> *). StructI a => ríki a a In the instance declaration for ‘Category (Hom ríki)’ |29 | i :: forall a. StructI a => Hom ríki a a | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^Bug.hs:30:12: error: • Could not deduce: cls1 a1 arising from a use of ‘struct’ from the context: Category ríki bound by the instance declaration at Bug.hs:28:10-65 or from: StructI a bound by the type signature for: i :: forall (a :: Struct cls0). StructI a => Hom ríki a a at Bug.hs:29:8-42 • In the expression: struct :: AStruct (Structured a cls) In the expression: case struct :: AStruct (Structured a cls) of In an equation for ‘i’: i = case struct :: AStruct (Structured a cls) of |30 | i = case struct :: AStruct (Structured a cls) of | ^^^^^^
Actually, this program //doesn't// hang—it actually produces a stack overflow after a certain amount of time!
$ time ~/Software/ghc2/inplace/bin/ghc-stage2 Bug.hs[1 of 1] Compiling Bug ( Bug.hs, Bug.o )stack overflow: use +RTS -K<size> to increase itreal 0m18.986suser 0m18.472ssys 0m0.540s$ ~/Software/ghc2/inplace/bin/ghc-stage2 --versionThe Glorious Glasgow Haskell Compilation System, version 8.5.20180221
Here's what this looks like in -ddump-tc-trace:
runStage interact with inerts { workitem = [WD] $dStructI_a1MK {0}:: StructI (Structured a_a1LU[sk:4] (cls_a1Li[ssk:2] |> {co_a1M2} ->_N <Constraint>_N)) (CDictCan)addFunDepWork [WD] $dStructI_a1MK {0}:: StructI (Structured a_a1LU[sk:4] (cls_a1Li[ssk:2] |> {co_a1M2} ->_N <Constraint>_N)) arising from a use of ‘struct’ at Bug.hs:32:12-17 False arising from the type signature for: i :: forall (a :: Struct cls). StructI a => Hom ríki_a1Lj[ssk:2] a a at Bug.hs:31:8-42 True arising from a functional dependency between constraints: ‘StructI (Structured a_a1LU[sk:4] (cls_a1Li[ssk:2] |> {co_a1M2} ->_N <Constraint>_N))’ arising from a use of ‘struct’ at Bug.hs:32:12-17 ‘StructI a_a1LU[sk:4]’ arising from the type signature for: i :: forall (a :: Struct cls). StructI a => Hom ríki_a1Lj[ssk:2] a a at Bug.hs:31:8-42 at Bug.hs:32:12-17 Falseend stage interact with inerts }runStage top-level reactions { workitem = [WD] $dStructI_a1MK {0}:: StructI (Structured a_a1LU[sk:4] (cls_a1Li[ssk:2] |> {co_a1M2} ->_N <Constraint>_N)) (CDictCan)doTopReact [WD] $dStructI_a1MK {0}:: StructI (Structured a_a1LU[sk:4] (cls_a1Li[ssk:2] |> {co_a1M2} ->_N <Constraint>_N)) (CDictCan)*** Exception: stack overflow
In case you're worried about that UndecidableInstances part, here's a version that doesn't use UndecidableInstances:
{-# LANGUAGE AllowAmbiguousTypes #-}{-# LANGUAGE ConstraintKinds #-}{-# LANGUAGE EmptyCase #-}{-# LANGUAGE FlexibleInstances #-}{-# LANGUAGE GADTs #-}{-# LANGUAGE InstanceSigs #-}{-# LANGUAGE MultiParamTypeClasses #-}{-# LANGUAGE ScopedTypeVariables #-}{-# LANGUAGE TypeInType #-}moduleBugwhereimportData.KindimportData.ProxytypeCatob=ob->ob->TypedataStruct::(k->Constraint)->TypewhereS::Proxy(a::k)->Struct(cls::k->Constraint)typeStructuredacls=(S('Proxy::Proxya)::Structcls)dataAStruct::Structcls->TypewhereAStruct::clsa=>AStruct(Structuredacls)classStructIxx(structured::Struct(cls::k->Constraint))wherestruct::AStructstructuredinstance(Structuredxxcls~structured,clsxx)=>StructIxxstructuredwherestruct::AStruct(Structuredxxcls)struct=AStructdataHom::Catk->Cat(Structcls)whereclassCategory(cat::Catob)wherei::StructIxxa=>ríkiaainstanceCategoryríki=>Category(Homríki::Cat(Structcls))wherei::forallxxa.StructIxxa=>Homríkiaai=casestruct::AStruct(Structuredacls)of
commit e99fdf775540440c1c58dc5ade3c5984dc49246fAuthor: Simon Peyton Jones <simonpj@microsoft.com>Date: Mon Feb 26 17:44:55 2018 +0000 Fix a nasty bug in the pure unifier The pure unifier was building an infinite type, through a defective occurs check. So GHC went into an infinite loop. Reason: we were neglecting the 'kco' part of the type, which 'unify_ty' maintains. Yikes. The fix is easy. I refactored a bit to make it harder to go wrong in future.>---------------------------------------------------------------e99fdf775540440c1c58dc5ade3c5984dc49246f compiler/types/Unify.hs | 59 ++++++++++++++++++--------------- testsuite/tests/polykinds/T14846.hs | 39 ++++++++++++++++++++++ testsuite/tests/polykinds/T14846.stderr | 43 ++++++++++++++++++++++++ testsuite/tests/polykinds/all.T | 1 + 4 files changed, 116 insertions(+), 26 deletions(-)
Richard, can you just check my work? I'll leave the ticket open, but assign to you.