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,346
    • Issues 5,346
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 567
    • Merge requests 567
  • 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
  • #3826
Closed
Open
Issue created Jan 19, 2010 by spl@trac-spl

Can't infer type (type family as "element" type)

Suppose I have a class C,

class C a where
  type E a
  c :: E a -> a -> a

a datatype T,

data T a = T a

and an instance of C for T

instance C (T a) where
  type E (T a) = a
  c x (T _) = T x

I would like to write a function such as f

f t@(T x) = c x t

without a type signature. Unfortunately, I can't because GHC tells me

    Couldn't match expected type `t' against inferred type `T (E t)'
    In the second argument of `c', namely `t'
    In the expression: c x t
    In the definition of `f': f (t@(T x)) = c x t

There are at least three possible ways to write the above code such that it works.

(1) Give a type signature for f

f :: T a -> T a

(2) Define the class C using an equality constraint

class C t where
  type E t
  c :: (E t ~ e) => e -> t -> t

(3) Define the class C using functional dependencies

class C t e | t -> e where
  c :: e -> t -> t

But the real question is why don't I get a type for f?

This has been tested in GHC 6.10.1 and 6.12.1.

Trac metadata
Trac field Value
Version 6.12.1
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler (Type checker)
Test case
Differential revisions
BlockedBy
Related
Blocking
CC leather@cs.uu.nl
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