2
votes

The language extension ExplicitForall makes it possible but not required to bind type variables with forall.

For example, the following program compiles

{-# LANGUAGE ExplicitForAll #-}

-- cps1.hs

-- non-cps definition of add
add :: Int -> Int -> Int
add x y = x + y

-- cps definition of add
add_cps :: forall r . Int -> Int -> (Int -> r) -> r
add_cps x y k = k (add x y)

However, the following program without an explicit quantifier for r also compiles.

{-# LANGUAGE ExplicitForAll #-}

-- cps2.hs

-- non-cps definition of add
add :: Int -> Int -> Int
add x y = x + y

-- cps definition of add
add_cps :: Int -> Int -> (Int -> r) -> r
add_cps x y k = k (add x y)

Is there some combination of language extensions or compiler flags that can make the second program fail to compile?

1
I don't think this is possible to achieve, with the current GHC.chi
I'm interested as to why you'd want the second to fail?AJF
@AJFarmar I could see it being useful to avoid confusing errors when you have ScopedTypeVariables turned on but forgot to bring a variable into scope with a forall.Daniel Wagner
Daniel's rationale is much better. I'm writing a generator for some Haskell code and want to the output to be processed with options that are as strict as possible.Gregory Nisbet

1 Answers

2
votes

No, GHC currently does not have tooling for that.