[Haskell-cafe] Issues(Bugs?) with GHC Type Families

David Menendez dave at zednenem.com
Fri Mar 7 13:22:13 EST 2008

On Fri, Mar 7, 2008 at 2:10 AM, Ryan Ingram <ryani.spam at gmail.com> wrote:

>  I don't think the cost is that great; the compiler can easily flag
>  polymorphic functions that require type information for some or all
>  arguments and in many cases the type evidence can be passed
>  "just-in-time" when calling from a non-polymorphic function into a
>  polymorphic function.

As I understand it, the cost in performance isn't too bad. For
example, JHC uses type-passing to implement type classes. One problem
is that a language with pervasive typecase has weaker guarantees. For
example, in present-day Haskell we can tell that length :: [a] -> Int
works the same for every type 'a' just by looking at the type
signature. That's not the case if we can call typecase in arbitrary

We can avoid that problem by requiring a type representation
parameter, or otherwise indicating the use of typecase in the
signature. Modern Haskell provides this with the Typeable class.
(Which, in JHC, is essentially empty.)

Thus, another solution for writing the show instance for lists is:

    class (Typeable a) => Show [a] where
        show s =
            case cast s of
                Just str -> "\"" ++ str ++"\""
                Nothing -> showList s
            where showList ...

To summarize: we can make more claims about a function with type
"forall a. F a -> G a" than one with type "forall a. (Typeable a) => F
a -> G a", even though every type can (as far as I know) be made an
instance of Typeable.

Dave Menendez <dave at zednenem.com>

More information about the Haskell-Cafe mailing list