Re: Evaluating type expressions in GHCi

Previous Topic Next Topic
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Re: Evaluating type expressions in GHCi

Brandon Moore-2
>From: Sean Leather <[hidden email]>
>I would like to ask GHCi for the type that a type expression will evaluate to, once all definitions of type synonyms and (when possible) type families have been inlined.
>It appears that I can do some part of this for type T by using ":t undefined :: T":
>undefined :: F (Int, Bool) :: (Bool, Int)
>I also get what I expect here:
>ghci> :t undefined :: F (a, Bool)
>undefined :: F (a, Bool) :: (F a, Int)
>Of course, this doesn't work on types of kinds other than *.

In the absence of interpreter support, you can work around that by making
appropriate type constructors.
{-# LANGUAGE TypeFamilies, KindSignatures, EmptyDataDecls #-}

type family G a :: * -> *
type instance G Int = Maybe
type instance G Bool = []

data Wrap1 (t :: * -> *)

ghci> :t undefined :: Wrap1 (G Int)
undefined :: Wrap1 (G Int) :: Wrap1 Maybe

The development version of ghci seems to support type declarations,
which would make this easier.


Haskell-Cafe mailing list
[hidden email]