Evaluating type expressions in GHCi
Simon Peyton-Jones
simonpj at microsoft.com
Fri Sep 23 10:04:54 CEST 2011
I did this.
*TF> :kind F Int
F Int :: *
*TF> :kind! F Int
F Int :: *
= Bool
In the end I just made an eager version of :kind as the command: in addition to displaying the kind of the type, it normalises it and shows the result.
It's in HEAD. Documentation to come when I get home.
I'm not wedded to this command name. If everyone wants ":normalise" it would only take a 1-line change.
Simon
From: glasgow-haskell-users-bounces at haskell.org [mailto:glasgow-haskell-users-bounces at haskell.org] On Behalf Of Sean Leather
Sent: 20 September 2011 11:34
To: GHC Users List
Subject: Evaluating type expressions in GHCi
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":
type family F a
type instance F Int = Bool
type instance F Bool = Int
type instance F (a, b) = (F a, F b)
ghci> :t undefined :: F (Int, Bool)
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 *.
Is it possible and worth having another GHCi command to perform this operation for any types? It could be the type analogue to :t such that it evaluates the type and gives its kind.
Regards,
Sean
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/glasgow-haskell-users/attachments/20110923/6b8d7e54/attachment.htm>
More information about the Glasgow-haskell-users
mailing list