Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GHC make explicit forall mandatory

Tags:

haskell

ghc

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?

like image 632
Gregory Nisbet Avatar asked Oct 25 '25 06:10

Gregory Nisbet


1 Answers

No, GHC currently does not have tooling for that.

like image 88
Daniel Wagner Avatar answered Oct 26 '25 22:10

Daniel Wagner



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!