[GHC] #10891: `reify` doesn't find associated type families

GHC ghc-devs at haskell.org
Thu Sep 17 21:55:39 UTC 2015


#10891: `reify` doesn't find associated type families
-------------------------------------+-------------------------------------
        Reporter:  antalsz           |                   Owner:
            Type:  bug               |                  Status:  new
        Priority:  normal            |               Milestone:  8.0.1
       Component:  Template Haskell  |                 Version:  7.10.2
      Resolution:                    |                Keywords:  type
                                     |  families; newcomer
Operating System:  Unknown/Multiple  |            Architecture:
 Type of failure:  Incorrect result  |  Unknown/Multiple
  at runtime                         |               Test Case:
      Blocked By:                    |                Blocking:
 Related Tickets:                    |  Differential Revisions:
-------------------------------------+-------------------------------------
Description changed by osa1:

Old description:

> Template Haskell's `reify` doesn't find the the associated type families
> of a type class.  Consider the following two classes:
>
> {{{#!hs
> class C a where
>   f :: a -> Int
>
> class C' a where
>   type F a :: *
>   f' :: a -> Int
> }}}
>
> These produce identical, up to renaming, output when passed to `reify`:
>
> {{{#!hs
> -- putStrLn $(stringE . show =<< reify ''C)
> ClassI (ClassD [] Ghci1.C [PlainTV a_1627398388] []
>                [SigD Ghci1.f
>                      (ForallT [PlainTV a_1627398388]
>                               [ClassP Ghci1.C [VarT a_1627398388]]
>                               (AppT (AppT ArrowT (VarT a_1627398388))
>                                     (ConT GHC.Types.Int)))])
>        []
>
> -- putStrLn $(stringE . show =<< reify ''C')
> ClassI (ClassD [] Ghci3.C' [PlainTV a_1627405973] []
>                [SigD Ghci3.f'
>                      (ForallT [PlainTV a_1627405973]
>                               [ClassP Ghci3.C' [VarT a_1627405973]]
>                               (AppT (AppT ArrowT (VarT a_1627405973))
>                                     (ConT GHC.Types.Int)))])
>        []
> }}}
>
> If I know the name of `F`, I can look up information about it:
>
> {{{!#hs
> -- putStrLn $(stringE . show =<< reify ''F)
> FamilyI (FamilyD TypeFam
>                  Ghci3.F
>                  [PlainTV a_1627405973]
>                  (Just StarT))
>         []
> }}}
>
> But I can't find the name of `F` in the first place.  Even if I add an
> instance of the type class, the `InstanceD` has none of the information
> about the definition.  Given
>
> {{{#!hs
> instance C' [a] where
>   type F [a] = a
>   f' = length
> }}}
>
> we get
>
> {{{#!hs
> -- putStrLn $(stringE . show =<< reify ''C')
> ClassI (ClassD [] Ghci3.C' [PlainTV a_1627405973] []
>                [SigD Ghci3.f'
>                      (ForallT [PlainTV a_1627405973]
>                               [ClassP Ghci3.C' [VarT a_1627405973]]
>                               (AppT (AppT ArrowT (VarT a_1627405973))
>                                     (ConT GHC.Types.Int)))])
>        [InstanceD []
>                   (AppT (ConT Ghci3.C')
>                         (AppT ListT (VarT a_1627406161)))
>                   []]
> }}}
>
> This problem was confirmed to exist in the following configurations:
>
> * GHC 7.10.2 with version 2.10.0.0 of the template-haskell package.
> * GHC 7.8.3 with version 2.9.0.0 of the template-haskell package.
> * GHC 7.4.2 with version 2.7.0.0 of the template-haskell package.
>
> (I also posted this on Stack Overflow in //2013//, where it has been
> languishing ever since: http://stackoverflow.com/q/17247880/237428.)

New description:

 Template Haskell's `reify` doesn't find the the associated type families
 of a type class.  Consider the following two classes:

 {{{#!hs
 class C a where
   f :: a -> Int

 class C' a where
   type F a :: *
   f' :: a -> Int
 }}}

 These produce identical, up to renaming, output when passed to `reify`:

 {{{#!hs
 -- putStrLn $(stringE . show =<< reify ''C)
 ClassI (ClassD [] Ghci1.C [PlainTV a_1627398388] []
                [SigD Ghci1.f
                      (ForallT [PlainTV a_1627398388]
                               [ClassP Ghci1.C [VarT a_1627398388]]
                               (AppT (AppT ArrowT (VarT a_1627398388))
                                     (ConT GHC.Types.Int)))])
        []

 -- putStrLn $(stringE . show =<< reify ''C')
 ClassI (ClassD [] Ghci3.C' [PlainTV a_1627405973] []
                [SigD Ghci3.f'
                      (ForallT [PlainTV a_1627405973]
                               [ClassP Ghci3.C' [VarT a_1627405973]]
                               (AppT (AppT ArrowT (VarT a_1627405973))
                                     (ConT GHC.Types.Int)))])
        []
 }}}

 If I know the name of `F`, I can look up information about it:

 {{{#!hs
 -- putStrLn $(stringE . show =<< reify ''F)
 FamilyI (FamilyD TypeFam
                  Ghci3.F
                  [PlainTV a_1627405973]
                  (Just StarT))
         []
 }}}

 But I can't find the name of `F` in the first place.  Even if I add an
 instance of the type class, the `InstanceD` has none of the information
 about the definition.  Given

 {{{#!hs
 instance C' [a] where
   type F [a] = a
   f' = length
 }}}

 we get

 {{{#!hs
 -- putStrLn $(stringE . show =<< reify ''C')
 ClassI (ClassD [] Ghci3.C' [PlainTV a_1627405973] []
                [SigD Ghci3.f'
                      (ForallT [PlainTV a_1627405973]
                               [ClassP Ghci3.C' [VarT a_1627405973]]
                               (AppT (AppT ArrowT (VarT a_1627405973))
                                     (ConT GHC.Types.Int)))])
        [InstanceD []
                   (AppT (ConT Ghci3.C')
                         (AppT ListT (VarT a_1627406161)))
                   []]
 }}}

 This problem was confirmed to exist in the following configurations:

 * GHC 7.10.2 with version 2.10.0.0 of the template-haskell package.
 * GHC 7.8.3 with version 2.9.0.0 of the template-haskell package.
 * GHC 7.4.2 with version 2.7.0.0 of the template-haskell package.

 (I also posted this on Stack Overflow in //2013//, where it has been
 languishing ever since: http://stackoverflow.com/q/17247880/237428.)

--

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/10891#comment:2>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list