Skip to content

type families: difference in type-checking between compile-time and run-time

in the module

{-# LANGUAGE TypeFamilies #-}

module Main where

import Prelude hiding (head)
import qualified Prelude

type family Elem a :: *

class ListLike t where
	head :: t -> Elem t

-- Instances

type instance Elem [a] = a

instance ListLike [a] where
	head = Prelude.head

x = head [1 :: Int,2,3]

main = putStrLn . show $ x

Here is the resulting interactive session, which I think is weird:

$ ghci Main
GHCi, version 6.9.20071027: http://www.haskell.org/ghc/  :? for help
Loading package base ... linking ... done.
[1 of 1] Compiling Main             ( Main.hs, interpreted )
Ok, modules loaded: Main.
*Main> :t x
x :: Elem [Int]
*Main> putStrLn . show $ x

<interactive>:1:11:
    No instance for (Show (Elem [Int]))
      arising from a use of `show' at <interactive>:1:11-14
    Possible fix: add an instance declaration for (Show (Elem [Int]))
    In the second argument of `(.)', namely `show'
    In the first argument of `($)', namely `putStrLn . show'
    In the expression: putStrLn . show $ x
*Main> main
1

Behavior is similar in GHC version 6.8.0.20071028

Trac metadata
Trac field Value
Version 6.8
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler
Test case
Differential revisions
BlockedBy
Related
Blocking
CC aslatter@gmail.com
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information