[GHC] #7095: Kind-polymorphic typechecking requires better documentation.

GHC cvs-ghc at haskell.org
Wed Jul 25 14:03:45 CEST 2012


#7095: Kind-polymorphic typechecking requires better documentation.
------------------------------+---------------------------------------------
 Reporter:  schernichkin      |          Owner:                   
     Type:  feature request   |         Status:  new              
 Priority:  normal            |      Component:  Documentation    
  Version:  7.4.2             |       Keywords:  Kind polymorphism
       Os:  Unknown/Multiple  |   Architecture:  Unknown/Multiple 
  Failure:  None/Unknown      |       Testcase:                   
Blockedby:                    |       Blocking:                   
  Related:                    |  
------------------------------+---------------------------------------------
 Hi. I faced some difficulties using kind-polymorphic instances and I think
 documentation should be improved. Consider following code:

 {{{
 {-# LANGUAGE DataKinds, TypeOperators, PolyKinds, FlexibleInstances,
 FlexibleContexts #-}

 data Wrapped t = Wrapped

 class Len l where
     len :: l -> Int

 instance Len (Wrapped '[]) where
     len = const 0

 instance (Len (Wrapped xs)) => Len (Wrapped (x ': xs)) where
     len x = 1 + (len $ wrappedTail x)

 wrappedTail :: Wrapped (x ': xs) -> Wrapped xs
 wrappedTail = const Wrapped

 -- | test1 == zero just as excepted.
 test1 = len (undefined  :: Wrapped '[])

 -- | Since I have typeclasses defined for Wrapped (* ': [*]) and for
 (Wrapped '[])
 -- I except to get 1 here, but this does not typecheck with following
 message:
 -- No instance for (Len (Wrapped [*] ([] *)))
 test2 = len (undefined  :: Wrapped '[Int])
 }}}

 It will not typecheck. Of couse it is possible to fix it by adding type
 signature to Wrapped:

 {{{
 {-# LANGUAGE DataKinds, TypeOperators, PolyKinds, FlexibleInstances,
 FlexibleContexts, KindSignatures #-}

 data Wrapped (t :: [*]) = Wrapped
 }}}

 but it is extremely hard to figure out relaying just on information
 provided here: http://www.haskell.org/ghc/docs/7.4.1/html/users_guide
 /kind-polymorphism-and-promotion.html, especially in complex scenarios. I
 think this page should provide more information on type-checker messages
 format related to polymorphic kind, and some common pitfalls.

-- 
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/7095>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler



More information about the Glasgow-haskell-bugs mailing list