Translation of global calls may be incorrect
Consider the following module that makes use of the Global
library.
import Global
ident :: a -> a
ident = \x -> x
test :: Global Bool
test = global (ident True) Temporary
Compiling this module results in the GHC error message .curry/kics2/Curry_TestGlobal.hs:26:15: Not in scope: ‘s’
referring to the generated Haskell code.
{-# LANGUAGE MagicHash #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# OPTIONS_GHC -fno-warn-overlapping-patterns #-}
module Curry_TestGlobal ( d_C_ident, d_C_test ) where
import Basics
import qualified Curry_Global
import qualified Curry_Prelude
d_C_ident :: forall t0 . (Curry_Prelude.Curry t0) => Cover -> ConstStore -> t0
-> Cover -> ConstStore -> t0
d_C_ident cd cs = d_OP_ident_dot_uscore_hash_lambda1
d_OP_ident_dot_uscore_hash_lambda1 :: forall t0 . (Curry_Prelude.Curry t0) => t0
-> Cover -> ConstStore -> t0
d_OP_ident_dot_uscore_hash_lambda1 x1 cd cs = x1
d_C_test :: Cover -> ConstStore -> Curry_Global.C_Global Curry_Prelude.C_Bool
d_C_test cd cs = global_C_test
global_C_test :: Curry_Global.C_Global Curry_Prelude.C_Bool
global_C_test = Curry_Global.d_C_global (let cs = emptyCs
cd = initCover
in let s0 = s
in s0 `seq` Curry_Prelude.nd_C_apply (wrapDX id (d_C_ident cd cs))
Curry_Prelude.C_True s0 cd cs) Curry_Global.C_Temporary initCover emptyCs
Apparently, the call to the deterministic function ident
(which returns a higher-order result) is wrapped in order to accept additional arguments including an ID supply. Unfortunately, this ID supply is never provided and, thus, the error occurs.
When you replace the definition of the function ident
with
ident x = x
the module compiles just fine (no higher-order result anymore). Then, the generated Haskell module is as follows.
{-# LANGUAGE MagicHash #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# OPTIONS_GHC -fno-warn-overlapping-patterns #-}
module Curry_TestGlobal ( d_C_ident, d_C_test ) where
import Basics
import qualified Curry_Global
import qualified Curry_Prelude
d_C_ident :: forall t0 . (Curry_Prelude.Curry t0) => t0 -> Cover -> ConstStore
-> t0
d_C_ident x1 cd cs = x1
d_C_test :: Cover -> ConstStore -> Curry_Global.C_Global Curry_Prelude.C_Bool
d_C_test cd cs = global_C_test
global_C_test :: Curry_Global.C_Global Curry_Prelude.C_Bool
global_C_test = Curry_Global.d_C_global (let cs = emptyCs
cd = initCover
in d_C_ident Curry_Prelude.C_True cd cs) Curry_Global.C_Temporary initCover
emptyCs
Of course, it cannot be ruled out that this translation error can also occur when not using the Global
library.