How does topological sorting of kind variables really work?
Ryan Scott
ryan.gl.scott at gmail.com
Wed Apr 13 02:55:39 UTC 2016
Well, I'd be hesitant to call it "reliable":
$ /opt/ghc/8.0.1/bin/ghci -XRankNTypes -XTypeInType
-fprint-explicit-foralls -fprint-explicit-kinds
GHCi, version 8.0.0.20160411: http://www.haskell.org/ghc/ :? for help
Loaded GHCi configuration from /home/ryanglscott/.ghci
> import Data.Proxy
> let wat :: forall (a :: j -> k -> l) (b :: (x, y, z)). Proxy a
-> Proxy b; wat = undefined
> :t wat
wat
:: forall {j} {k} {l} {x} {y} {z} {a :: j -> k -> l} {b :: (x, y,
z)}.
Proxy (j -> k -> l) a -> Proxy (x, y, z) b
> data Wat (a :: j -> k -> l) (b :: (x, y, z)) = Wat (Proxy a) (Proxy b)
> :t Wat
Wat
:: forall {x} {y} {z} {l} {k} {j} {a :: j -> k -> l} {b :: (x, y,
z)}.
Proxy (j -> k -> l) a -> Proxy (x, y, z) b -> Wat x y z l k j a b
In the example above, a plain old function gives me the ordering I'd
expect, but a data constructor does not. Now, maybe there's something
tricky involving data that makes this different - I'm not qualified
enough to say for sure. But it has made me a lot more paranoid about
checking the order of the variables with :t before I use
-XTypeApplications, since you never know what you're going to get
sometimes.
Ryan S.
On Tue, Apr 12, 2016 at 10:45 PM, Richard Eisenberg <eir at cis.upenn.edu> wrote:
>
> On Apr 12, 2016, at 10:44 PM, Ryan Scott <ryan.gl.scott at gmail.com> wrote:
>>
>> It's a bit of a shame that type inference doesn't give you a reliable
>> order, but I suppose if you rely on -XTypeApplications working a
>> certain way, you're taking a risk by NOT using a forall.
>
> Inference is meant to give you a reliable ordering. If it's not, that's a bug!
More information about the ghc-devs
mailing list