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?
ScopedTypeVariables
turned on but forgot to bring a variable into scope with aforall
. – Daniel Wagner