[Haskell] Implicit parameters
Per Larsson
per at L4i.se
Wed Jun 9 14:37:32 EDT 2004
When using implicit parameters I have noticed (at least for me) a rather
puzzling behaviour with GHC and Hugs.
Given the declarations
data Env = Env {numlines :: Int, numcols :: Int}
initEnv = Env {numlines = 0, numcols = 1}
withEnv :: ((?env :: Env) => IO a) -> IO a
withEnv io = let ?env = initEnv in io
I can write code like:
main = withEnv (do
let lines = numlines ?env
putStrLn ("Initial number of lines is " ++ (show lines)))
which works as expected, but the version below
main = withEnv $ do
let lines = numlines ?env
putStrLn ("Initial number of lines is " ++ (show lines))
is not accepted by either GHC or Hugs! Is this a bug or have stumbled into a
context where it actually matters if you use '$' or explicit grouping with
parentheses?
Per Larsson
More information about the Haskell
mailing list