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,870
    • Issues 4,870
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 453
    • Merge requests 453
  • 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
  • #5326
Closed
Open
Created Jul 15, 2011 by reinerp@trac-reinerp

Polymorphic instances aren't automatically specialised

Related to #255 (closed). Given (roughly) the example from that ticket:

f :: (Storable a, Eq a) => T a

g :: T (Ptr a)
g = f

we find that g is not specialised. Adding a SPECIALISE pragma fixes this, but it ought not to be necessary.

The following module is a complete example:

module C where

class C a where f :: a -> a

newtype Id a = Id a
instance C (Id a) where f = id

g :: C a => Int -> a -> a
g 0 a = a
g n a = g (n-1) (f a)

h :: Int -> Id a -> Id a
h = g

j :: Int -> Id Int -> Id Int
j = g

We find that h passes a dictionary to g:

C.h =
  \ (@ a_alq) (w_smq :: Int) (w1_smu :: C.Id a_alq) ->
    case w_smq of _ { I# ww_sms ->
    C.$wg @ (C.Id a_alq) (C.$fCId @ a_alq) ww_sms w1_smu
    }

whereas j is specialised as desired, getting its own worker and no dictionaries:

C.j =
  \ (w_smg :: Int) (w1_smk :: C.Id Int) ->
    case w_smg of _ { I# ww_smi ->
    (C.$wj ww_smi w1_smk)
    `cast` (sym (C.NTCo:Id Int)
            :: Int ~ C.Id Int)
    }

If we add

{-# SPECIALISE g :: Int -> Id a -> Id a #-}

then h is specialised as desired.

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