Opened 8 months ago

Closed 5 months ago

#9433 closed bug (fixed)

Partially applied type family allowed but unusable

Reported by: hesselink Owned by:
Priority: normal Milestone: 7.8.4
Component: Compiler (Type checker) Version: 7.9
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: GHC accepts invalid program Test Case: indexed-types/should_fail/T9433
Blocked By: Blocking:
Related Tickets: Differential Revisions:

Description

I was playing around with the following code, which tries to map a type family over a type (something I thought would not be allowed):

{-# LANGUAGE
    TypeFamilies
  , KindSignatures
  #-}

type family Id x :: *
type instance Id a = a

type family Map (f :: * -> *) x :: *
type instance Map f [a] = [f a]

x :: Map Id [Bool]
x = []

Both GHC 7.8.3 and the current HEAD (7.9.20140811) accept this program! However, changing the definition of x to [True] gives an error:

    Couldn't match type ‘Id Bool’ with ‘Bool’
    Expected type: Map Id [Bool]
      Actual type: [Bool]
    In the expression: [True]
    In an equation for ‘x’: x = [True]

If I define y :: Id Bool with value True (which works fine) and define x = [y], I even get this error:

    Couldn't match type ‘Bool’ with ‘Id Bool’
    Expected type: Id Bool
      Actual type: Id Bool
    In the expression: y
    In the expression: [y]

Change History (5)

comment:1 Changed 7 months ago by Simon Peyton Jones <simonpj@…>

In 8ff4671422090acf9146e3a90dd38e2c6f72aebb/ghc:

Make Core Lint check for un-saturated type applications

Un-saturated type-family and type-synonym applications are
detected in the front end, but for some reason Lint wasn't
looking for them.

I came across this when wondering why Trac #9433 didn't give
a Core Lint error

comment:2 Changed 7 months ago by Simon Peyton Jones <simonpj@…>

In ee4501bbad6480509e8a60b5ff89c0b0b228b66d/ghc:

Check for un-saturated type family applications

This patch corrects an egregious error introduced by:

  commit 022f8750edf6f413fba31293435dcc62600eab77
  Author: Simon Peyton Jones <[email protected]>
  Date:   Thu May 15 16:07:04 2014 +0100

    Refactoring around TyCon.isSynTyCon

    * Document isSynTyCon better
    * Add isTypeSyonymTyCon for regular H98 type synonyms
    * Use isTypeSynonymTyCon rather than isSynTyCon where
      the former is really intended

At this particular spot in TcValidity we really do mean
isSynTyCon and not isTypeSynonymTyCon.

Fixes Trac #9433

comment:3 Changed 7 months ago by simonpj

  • Status changed from new to merge
  • Test Case set to indexed-types/should_fail/T9433

Thanks for reporting this.

Austin: worth merging ee4501 if we make 7.8.4

Simon

comment:4 Changed 5 months ago by rodlogic

Related ticket was closed as a duplicate: #9733 (may contain additional information that is relevant here).

comment:5 Changed 5 months ago by thoughtpolice

  • Milestone set to 7.8.4
  • Resolution set to fixed
  • Status changed from merge to closed

Merged to ghc-7.8.

Note: See TracTickets for help on using tickets.