-
Notifications
You must be signed in to change notification settings - Fork 264
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Amend #281 (visible forall) and #378 (Design of DH) to clarify treatment of term variables in types #607
Amend #281 (visible forall) and #378 (Design of DH) to clarify treatment of term variables in types #607
Conversation
The proposal contradicts itself (elsewhere it says "Any uses of terms in types are ill-typed") and treating term variables as skolems can be handled in a later proposal
ping @int-index |
Concerning
I think that should be rejected. The binding for
where So I like this:
and I don't like this
Now, it is true that GHC proposal #378: design for Dependent Haskell says in Section 4.6:
which suggests that we accept the above program but without exploiting the knowledge of what |
Copying my comment from #23717 which I think addresses that point: Imagine you have foo :: foreach (str :: String) -> <some type involving str>
foo str = ...
main :: IO ()
main = do
str <- readLine
let result = foo str
... Here, we want to use a function that uses The way singletons handles this is with a function called |
First of all, I support the amendment. The proposal shouldn't contradict itself. Thank you @JakobBruenker for spotting this problem! There are two ways to resolve the contradiction:
Simon expresses skepticism about the usefulness of option 2. I don't share this skepticism; on the contrary, I am rather excited about the possibility to mention term-level variables at the type level. The example in @JakobBruenker's last comment has the right idea. I can offer a similar example, a bit more concrete: vReplicateA :: Applicative f => foreach (n :: Nat) -> f a -> f (Vec n a)
vReplicateA Z _ = pure VNil
vReplicateA (S n') act = liftA2 VCons act (vRelicateM n' act)
vZip :: Vec n a -> Vec n b -> Vec n (Tuple2 a b)
vZip VNil VNil = VNil
vZip (VCons x xs) (VCons y ys) = VCons (x, y) (vZip xs ys)
mkInt :: IO Int
mkBool :: IO Bool
h :: Vec n (Tuple2 Int Bool) -> IO Unit
main = do
let n :: Nat
n = ... -- or a monadic bind (n <- ...) if you will
intVec <- vReplicateA n mkInt
boolVec <- vReplicateA n mkBool
h (vZip intVec boolVec) In Note that this example also relies on So #378 has this skolem clause for a good reason. But should it be in #281? I can't think of a useful example that would use |
OK I'm convinced. Thank you for explaining so patiently.
That is a very helpful insight. My conclusion
To be constructive, how about this:
Then our future selves, reading these proposals, will be able to make sense of it all. Thanks! @rae may have a view. |
(wrong @rae, you presumably meant to ping @goldfirere) |
Regarding your suggestions @simonpj, I agree, I will change the PR accordingly. |
I've made the changes @simonpj suggested. |
thanks. But can you add a corss ref here saying "(see Section 4.5)"? Because Also I stumbled on "retained quantifier". Actually this in in 4.4 but I'm not famililar with the terminology. So lets have:
|
Sounds good, I've made that change (slightly adapted because I can't figure out how to make a working link where section name and link text differ) |
@nomeata I think this is ready to go to the comittee. CC @int-index |
I'm in support. Helpful clarification. |
Say you have
Here, we're passing the term variable
x
as argument tof
, which expects a type. Is this allowed? #281 saysso the answer is no.
But it also says
...so the answer is yes?
In a brief discussion in GHC issue #23717 we agreed that this particular aspect of #378 can wait until a later proposal.
Update: We also use this opportunity to expand somewhat on the explanation of term variables in types in #378.