语言扩展 ExplicitForall
使得使用 forall
绑定(bind)类型变量成为可能但不是必需的。
例如,下面的程序可以编译
{-# 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)
但是,以下没有显式 r
量词的程序也可以编译。
{-# 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)
是否有某种语言扩展或编译器标志的组合可以使第二个程序无法编译?
最佳答案
不,GHC 目前没有这方面的工具。
关于haskell - GHC 明确强制要求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51830730/