Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
  • GHC GHC
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 5,255
    • Issues 5,255
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 562
    • Merge requests 562
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Deployments
    • Deployments
    • Releases
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Code review
    • Insights
    • Issue
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Glasgow Haskell CompilerGlasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #14440
Closed
Open
Issue created Nov 07, 2017 by Ryan Scott@RyanGlScottMaintainer

Duplicate type family instances are permitted

This threw me for a loop recently. To my surprise, GHC is quite happy to allow duplicate type family instances, provided that their RHSes are the same:

{-# LANGUAGE TypeFamilies #-}
module Lib where

type family Foo b
{-# LANGUAGE TypeFamilies #-}
module A where

import Lib

type instance Foo Bool = Bool
{-# LANGUAGE TypeFamilies #-}
module B where

import Lib

type instance Foo Bool = Bool
module C where

import A
import B
import Lib

f :: Bool -> Foo Bool
f x = not x
$ /opt/ghc/8.2.1/bin/ghci C.hs
GHCi, version 8.2.1: http://www.haskell.org/ghc/  :? for help
Loaded GHCi configuration from /home/rgscott/.ghci
[1 of 4] Compiling Lib              ( Lib.hs, interpreted )
[2 of 4] Compiling B                ( B.hs, interpreted )
[3 of 4] Compiling A                ( A.hs, interpreted )
[4 of 4] Compiling C                ( C.hs, interpreted )
Ok, 4 modules loaded.
λ> :i Foo
type family Foo b :: *  -- Defined at Lib.hs:4:1
type instance Foo Bool = Bool   -- Defined at A.hs:6:15
type instance Foo Bool = Bool   -- Defined at B.hs:6:15

Is this intended? My intuition screams "no", since if we offer //class// instance coherence, it seems like one ought to offer //type family// instance coherence as well. At the same time, I can't think of any threat to type soundness imposed by this (although it's quite strange to see two duplicate type family instances in the output of :i with two completely different provenances).

Trac metadata
Trac field Value
Version 8.2.1
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler (Type checker)
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking