
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

Sean Yes, this has been asked for before, and it wouldn't be hard to implement. What should the GHCi command be *called*? We already have :kind, which displays the kind of a type. Maybe :kind! should evaluate the type as well? Or perhaps :kind should evaluate anyway (although that would be a bit inconsistent with :type which does not evaluate the expression) Or :normtype? short for normalise type Simon From: glasgow-haskell-users-bounces@haskell.org [mailto:glasgow-haskell-users-bounces@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

Would it be possible to have no command at all? Types are
distinguished by upper-case letters, so it should be possible to tell
whether a given expression is a value-level or a type-level expression.
I guess that's not strictly true, since the expression could be _only_
type variables -- but then I think it would be forgivable to just use
the value-level evaluator for those ambiguous ones.
~d
Quoting Simon Peyton-Jones
Sean
Yes, this has been asked for before, and it wouldn't be hard to implement.
What should the GHCi command be *called*?
We already have :kind, which displays the kind of a type. Maybe :kind! should evaluate the type as well? Or perhaps :kind should evaluate anyway (although that would be a bit inconsistent with :type which does not evaluate the expression)
Or :normtype? short for normalise type
Simon
From: glasgow-haskell-users-bounces@haskell.org [mailto:glasgow-haskell-users-bounces@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

type family Bar a :: *
type instance Bar () = String
data Foo a = Bar a | Baz a a
ghci> Bar ()
What happens?
There is a lot of ambiguity between term and type levels in Haskell.
(,); []; etc. It's only the overall structure of the language that
disambiguates them; you can't necessarily tell just by looking at an
expression and the existing definitions in scope.
-- Dan
On Tue, Sep 20, 2011 at 7:02 PM,
Would it be possible to have no command at all? Types are distinguished by upper-case letters, so it should be possible to tell whether a given expression is a value-level or a type-level expression.
I guess that's not strictly true, since the expression could be _only_ type variables -- but then I think it would be forgivable to just use the value-level evaluator for those ambiguous ones.
~d
Quoting Simon Peyton-Jones
: Sean
Yes, this has been asked for before, and it wouldn't be hard to implement.
What should the GHCi command be *called*?
We already have :kind, which displays the kind of a type. Maybe :kind! should evaluate the type as well? Or perhaps :kind should evaluate anyway (although that would be a bit inconsistent with :type which does not evaluate the expression)
Or :normtype? short for normalise type
Simon
From: glasgow-haskell-users-bounces@haskell.org [mailto:glasgow-haskell-users-bounces@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
_______________________________________________ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users

On Wednesday 21 September 2011, 01:02:52, wagnerdm@seas.upenn.edu wrote:
Would it be possible to have no command at all? Types are distinguished by upper-case letters, so it should be possible to tell whether a given expression is a value-level or a type-level expression.
Unless I'm misunderstanding, no: {-# LANGUAGE TypeFamilies #-} module TFEx where type family F a type instance F Int = Bool type instance F Bool = Int type instance F (a, b) = (F a, F b) data Foo a = F a deriving Show data Moo = Int | Bool deriving Show *TFEx> F (Int,Bool) F (Int,Bool) *TFEx> :t F (Int,Bool) F (Int,Bool) :: Foo (Moo, Moo) *TFEx> :t undefined :: F (Int,Bool) undefined :: F (Int,Bool) :: (Bool, Int) *TFEx>

On Tue, Sep 20, 2011 at 3:44 PM, Simon Peyton-Jones
What should the GHCi command be *called*?
:simplify or :simplifytype. In GHCi at the moment, you could abbreviate that as short as :si. /g -- "I’m surprised you haven’t got a little purple space dog, just to ram home what an intergalactic wag you are."

On Tue, Sep 20, 2011 at 04:29:21PM -0700, J. Garrett Morris wrote:
On Tue, Sep 20, 2011 at 3:44 PM, Simon Peyton-Jones
wrote: What should the GHCi command be *called*?
:simplify or :simplifytype. In GHCi at the moment, you could abbreviate that as short as :si.
IMO Simon's suggestion of something like :normalizetype or :normalize or :normtype would be even better -- you could abbreviate it as just :n . It is also more accurate; the correct term for what the command should do is in fact "normalize", and it may not in fact end up making the type any simpler. -Brent

On Wed, Sep 21, 2011 at 04:00, Brent Yorgey wrote:
On Tue, Sep 20, 2011 at 04:29:21PM -0700, J. Garrett Morris wrote:
On Tue, Sep 20, 2011 at 3:44 PM, Simon Peyton-Jones wrote:
What should the GHCi command be *called*?
:simplify or :simplifytype. In GHCi at the moment, you could abbreviate that as short as :si.
IMO Simon's suggestion of something like :normalizetype or :normalize or :normtype would be even better -- you could abbreviate it as just :n . It is also more accurate; the correct term for what the command should do is in fact "normalize", and it may not in fact end up making the type any simpler.
I like :normalize (without "type" since we don't need to distinguish it from term normalization), and the shorthand :n is perfect. And if you prefer :normalise, the location-agnostic :normtype, or other colors that start with :n, I don't mind, because I'll almost never type the whole thing. ;) Regards, Sean

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@haskell.org [mailto:glasgow-haskell-users-bounces@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

Hi Simon, On Fri, Sep 23, 2011 at 10:04, Simon Peyton-Jones wrote:
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.
That's great! Much appreciated. I’m not wedded to this command name. If everyone wants “:normalise” it
would only take a 1-line change.
I'm also not picky about the name. But I do think fewer keystrokes are better. I guess with ":kind!" you have have to type at least ':', 'k', '\t', and '!', whereas with a unique first character such as 'n', you only have to type ':', 'n' [1]. But that's the only real "concern" I would have about the name. Safe travels! Regards, Sean [1] This presupposes that people actually want to use such a command. It does make working with type families easier. And, now that I think about it, I needed something like that this several years ago. http://splonderzoek.blogspot.com/2009/06/rfc-extensible-typed-scanf-and-prin...

Yes, it expands type synonyms too S From: sean.leather@gmail.com [mailto:sean.leather@gmail.com] On Behalf Of Sean Leather Sent: 23 September 2011 13:43 To: Simon Peyton-Jones Cc: GHC Users List Subject: Re: Evaluating type expressions in GHCi Hi Simon, *TF> :kind F Int F Int :: * *TF> :kind! F Int F Int :: * = Bool Does this also work with plain ol' type synonyms? I just noticed that the ":t undefined :: T" trick doesn't seem to work with type synonyms. Thanks, Sean
participants (7)
-
Brent Yorgey
-
Dan Doel
-
Daniel Fischer
-
J. Garrett Morris
-
Sean Leather
-
Simon Peyton-Jones
-
wagnerdm@seas.upenn.edu