Consider the Haskell functions
test :: ST s [Int]
test = do
arr <- newListArray (0,9) [0..9] :: ST s (STArray s Int Int)
let f i = do writeArray arr i (2*i)
readArray arr i
forM [1,2] f
and
test' :: ST s [Int]
test' = do
arr <- newListArray (0,9) [0..9] :: ST s (STArray s Int Int)
let f = \i -> do writeArray arr i (2*i)
readArray arr i
forM [1,2] f
The first requires FlexibleContexts to compile on ghci 8.10.1, the second compiles with no extra options. Why?
An answer that explains this behaviour in terms of the scope of the type variable s
would be especially welcome. As a follow up, what (if any) type signature can be added to the function f
to make test
compile without FlexibleContexts? Finally, is there a connection with the monomorphism restriction?