Opened 7 years ago

Last modified 9 months ago

#1496 closed bug

System FC{Newtypes,TypeFamilies} is unsound — at Initial Version

Reported by: sorear Owned by:
Priority: normal Milestone: 7.6.2
Component: Compiler (Type checker) Version: 6.7
Keywords: Cc: samb, chak@…, ganesh.sittampalam@…, lennart.augustsson@…, tom.schrijvers@…, df@…, mjm2002@…, pumpkingod@…, ben@…, jmaessen@…, hackage.haskell.org@…, ezyang@…
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Difficulty: Unknown
Test Case: Blocked By:
Blocking: Related Tickets:

Description

{-# OPTIONS_GHC -ftype-families #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
data family Z :: * -> *

class IsInt t where
    isInt :: c Int -> c t
instance IsInt Int where isInt = id

newtype Moo = Moo Int deriving(IsInt)

newtype instance Z Int = ZI Double
newtype instance Z Moo = ZM (Int,Int)

main = case isInt (ZI 4.0) of ZM tu -> print tu
stefan@stefans:/tmp$ ghc -dcore-lint Z.hs
stefan@stefans:/tmp$ ./a.out
Segmentation fault
stefan@stefans:/tmp$ ghc -V
The Glorious Glasgow Haskell Compilation System, version 6.7.20070612
stefan@stefans:/tmp$

It does not appear possible to tickle this without using the newtype-deriving
hack, but as the resulting core passes Core Lint this is othogonal to that bug.
The family of axioms produced is inconsistant:

(from the instances)
Z Int ~ Double
Z Moo ~ (Int,Int)

(from the newtype)
Moo ~ Int

(production REFL in the FC(X) paper)
Z ~ Z

(production COMP)
Z Moo ~ Z Int

(production TRANS)
Z Moo ~ Double

(production SYM)
Double ~ Z Moo

(production TRANS)
Double ~ (Int,Int)

Change History (0)

Note: See TracTickets for help on using tickets.