Implicit parameters:

Question regarding implicit parameters... The GHC manual says: "Dynamic binding constraints behave just like other type class constraints in that they are automatically propagated." But the following code produces an error: --------------------------------------------------------------------------------------------------------- main = do var <- newIORef (0::Int) let ?global_counter = var in f f = do a <- get_unique putStr (showInt a "\n") b <- get_unique putStr (showInt b "\n") c <- get_unique putStr (showInt c "\n") get_unique :: (?global_counter :: IORef Int) => IO Int get_unique = readIORef ?global_counter ---------------------------------------------------------------------------------------------------------- If "(?global_counter :: IORef Int)" were a class constraint the type signature for 'f' could be derived automatically... but we get: Unbound implicit parameter (?global_counter::IORef a) arising from use of `get_unique' at Test.hs:17:13-22 Is this a bug? Is there some reason why this is not possible? (and if it is not possible shouldn't the documentation be changed to reflect this)... Keean.

Isn't it just the monomorphism restriction at work? This works fine:
f () = do a <- get_unique putStr (showInt a "\n") b <- get_unique putStr (showInt b "\n") c <- get_unique putStr (showInt c "\n")
get_unique :: (?global_counter :: IORef Int) => IO Int get_unique = readIORef ?global_counter
J.A.

Yes, adding -fno-monomorphism-restriction allows the example to compile. I guess I got confused by the error message, expecting it to mention the monomorphism restriction directly... I'm sure it does sometimes. Any chance of improving the error message for this? Jorge Adriano Aires wrote:
Isn't it just the monomorphism restriction at work? This works fine:
participants (2)
-
Jorge Adriano Aires
-
Keean Schupke