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 563
    • Merge requests 563
  • 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
  • #8889
Closed
Open
Issue created Mar 13, 2014 by MikeIzbicki@trac-MikeIzbicki

GHCI reports nasty type signatures

Load a file that contains:

{-# LANGUAGE TypeFamilies
           , ConstraintKinds
           , MultiParamTypeClasses
           , UndecidableInstances
           , FlexibleInstances 
  #-}

import GHC.Prim
import Prelude hiding (Functor(..))

class Functor f where
    type C_fmap_a f a :: Constraint
    type C_fmap_a f a = ()
    type C_fmap_b f b :: Constraint
    type C_fmap_b f b = ()
    fmap :: (C_fmap_a f a, C_fmap_b f b) => (a -> b) -> f a -> f b

    fmap1 :: (ValidFunctor f a, ValidFunctor f b) => (a -> b) -> f a -> f b
    fmap2 :: (ValidFunctor' f a, ValidFunctor' f b) => (a -> b) -> f a -> f b

type ValidFunctor f a = 
    ( Functor f
    , C_fmap_a f a
    , C_fmap_b f a
    )
    
class ValidFunctor f a => ValidFunctor' f a
instance ValidFunctor f a => ValidFunctor' f a
                                            

Then check the following types in ghci

ghci> :t fmap
fmap
  :: (t, t1, Functor f, C_fmap_b f b ~ t1, C_fmap_a f a ~ t) =>
     (a -> b) -> f a -> f b

ghci> :t fmap1
fmap1
  :: (t, t1, t2, t3, Functor f, C_fmap_b f b ~ t3, C_fmap_b f a ~ t1,
      C_fmap_a f b ~ t2, C_fmap_a f a ~ t) =>
     (a -> b) -> f a -> f b

ghci> :t fmap2
fmap2
  :: (t, t1, t2, t3, Functor f, C_fmap_b f b ~ t3, C_fmap_b f a ~ t1,
      C_fmap_a f b ~ t2, C_fmap_a f a ~ t) =>
     (a -> b) -> f a -> f b

These types are much nastier looking than they need to be. There are two problems:

  1. Bogus types t,t1,t2,t3 are introduced when they don't need to be. This is confuses the type signatures quite a bit.

  2. The type alias ValidFunctor is being desugared in the type signature for fmap1. This makes type aliases for constraints rather pointless.

Also, I tried to solve problem two by adding an extra class, and hoping the class would be displayed instead, but this still doesn't work. I assume this is actually intended behavior though.

Trac metadata
Trac field Value
Version 7.8.1-rc1
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component GHCi
Test case
Differential revisions
BlockedBy
Related
Blocking
CC hvr
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