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,247
    • Issues 5,247
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 574
    • Merge requests 574
  • 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
  • #7967
Closed
Open
Issue created Jun 06, 2013 by Richard Eisenberg@raeDeveloper

With dependent types, error reported in seemingly unrelated function

In doing some routine dependently typed hackery, I wrote the following:

{-# LANGUAGE TypeFamilies, DataKinds, TypeOperators, GADTs #-}

data Nat = Zero | Succ Nat

data SNat :: Nat -> * where
  SZero :: SNat Zero
  SSucc :: SNat n -> SNat (Succ n)

data HList :: [*] -> * where
  HNil :: HList '[]
  HCons :: h -> HList t -> HList (h ': t)

data Index :: Nat -> [*] -> * where
  IZero :: Index Zero (h ': t)
  ISucc :: Index n l -> Index (Succ n) (h ': l)

type family Lookup (n :: Nat) (l :: [*]) :: *
type instance Lookup Zero (h ': t) = h
type instance Lookup (Succ n) (h ': t) = Lookup n t

hLookup :: Index n l -> HList l -> Lookup n l
hLookup IZero (HCons h _) = h
hLookup (ISucc n) (HCons _ t) = hLookup n t
hLookup _ _ = undefined

So far, so good. But, I wanted a way to convert SNats to Indexes. When I add the (wrong) code below

sNatToIndex :: SNat n -> HList l -> Index n l
sNatToIndex SZero HNil = IZero

I get an error in the second clause of hLookup, '''even though I haven't touched hLookup'''. (I also get an error in sNatToIndex, but that one's OK.)

The error is this:

/Users/rae/temp/Bug.hs:23:33:
    Couldn't match type ‛t1’ with ‛Lookup n l’
      ‛t1’ is untouchable
        inside the constraints (l ~ (':) * h1 t)
        bound by a pattern with constructor
                   HCons :: forall h (t :: [*]). h -> HList t -> HList ((':) * h t),
                 in an equation for ‛hLookup’
        at /Users/rae/temp/Bug.hs:23:20-28
    Expected type: Lookup n l
      Actual type: Lookup n1 l1
    Relevant bindings include
      hLookup :: Index n l -> HList l -> Lookup n l
        (bound at /Users/rae/temp/Bug.hs:22:1)
    In the expression: hLookup n t
    In an equation for ‛hLookup’:
        hLookup (ISucc n) (HCons _ t) = hLookup n t

This was tested with 7.7.20130528.

Trac metadata
Trac field Value
Version 7.7
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