Skip to content

GitLab

  • Menu
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 4,866
    • Issues 4,866
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 461
    • Merge requests 461
  • 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 Compiler
  • GHCGHC
  • Issues
  • #10450
Closed
Open
Created May 27, 2015 by sjcjoosten@sjc

Poor type error message when an argument is insufficently polymorphic

When pattern matching, "let/where" and "case" have different behaviours.

Currently, this is accepted (a version using 'where' instead of 'let' type-checks too):

{-# LANGUAGE RankNTypes, ScopedTypeVariables #-}
module Main where

data Phantom x = Phantom Int deriving Show

foo :: forall y. (forall x. (Phantom x)) -> Phantom y
foo (Phantom x) = Phantom (x+1)
-- trying to map foo over a list, this is the only way I can get it to work
typeAnnotatedMap :: (forall x. [Phantom x])
                 -> [Phantom y]
typeAnnotatedMap intList = case intList of
                             [] -> []
                             _ -> let (phead:ptail) = intList
                                  in  foo phead : typeAnnotatedMap ptail

The following are not accepted:

typeAnnotatedMap1 :: (forall x. [Phantom x])
                 -> [Phantom y]
typeAnnotatedMap1 intList = case intList of
                             [] -> []
                             (phead:ptail) -> foo phead : typeAnnotatedMap1 ptail

typeAnnotatedMap2 :: (forall x. [Phantom x])
                 -> [Phantom y]
typeAnnotatedMap2 [] = []
typeAnnotatedMap2 (phead:ptail) = foo phead : typeAnnotatedMap2 ptail

The current type error is something like:

Couldn't match type ‘x0’ with ‘x’
      because type variable ‘x’ would escape its scope
    This (rigid, skolem) type variable is bound by
      a type expected by the context: [Phantom x]

More helpful would be something like:

Your pattern match bound the following types to a shared skolem variable:
      ptail :: [Phantom x0] (bound at rankNtest.hs:11:25)
      phead :: Phantom x0 (bound at rankNtest.hs:11:19)
You may have intended to use a "let" or "where" pattern-match instead.
Edited Mar 10, 2019 by sjcjoosten
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking