Confused about specified type variables using -XTypeApplications
Andres Loeh
mail at andres-loeh.de
Thu Jan 7 18:39:40 UTC 2016
Hi.
I just today had a very similar problem with a kind-polymorphic class
definition. Simplified example (with ScopedTypeVariables, TypeInType,
TypeApplications):
GHCi> class C a where c :: ()
GHCi> :t c
c :: forall k (a :: k). C a => ()
GHCi> :t c @Int
c @Int :: C a => ()
GHCi> :t c @_ @Int
c @_ @Int :: C Int => ()
GHCi> let d :: forall a . C a => (); d = c @_ @a
GHCi> :t d
d :: forall k (a :: k). C a => ()
GHCi> :t d @Int
d @Int :: C Int => ()
I find it particularly confusing that GHCi prints the types of c and d
in exactly the same way, yet treats explicit type application on them
differently.
Cheers,
Andres
On Thu, Jan 7, 2016 at 6:54 PM, Ryan Scott <ryan.gl.scott at gmail.com> wrote:
> I read in the Visible Type Applications paper [1] that you can only
> apply types to "specified" type variables. However, after trying out
> -XTypeApplications, I'm confused as to what exactly that means:
>
> $ /opt/ghc/head/bin/ghci
> GHCi, version 8.1.20160106: http://www.haskell.org/ghc/ :? for help
> λ> :set -XTypeInType -XTypeApplications
> λ> data Prox a = Prox
> λ> let prox :: Prox a; prox = Prox
> λ> :t prox @Int
> prox @Int :: Prox Int
> λ> :t Prox @Int
> Prox @Int :: Prox a
>
> Huh? For some reason, I'm getting different types for prox @Int and
> Prox @Int! I think what's happening here is that in Prox @Int, the Int
> is being applied to a kind variable. That is, it's being applied to
> the k variable in:
>
> Prox :: forall k (t :: k). Prox t
>
> But why is this? After all, I don't think I "specified" k anywhere in
> the definition of Prox, and to make things more confusing, Int gets
> applied differently in prox @Int (and the definition of prox also
> doesn't mention k). Is this a bug, or am I misunderstanding something
> about -XTypeApplications?
>
> Ryan S.
> -----
> [1] http://www.cis.upenn.edu/~eir/papers/2016/type-app/visible-type-app.pdf
> _______________________________________________
> ghc-devs mailing list
> ghc-devs at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs
More information about the ghc-devs
mailing list