Monomorphism by annotation of type variables
Jump to navigation
Jump to search
Introduce the reserved word monomo
for rendering type variables monomorphic:
newIORef :: monomo a . a -> IO (IORef a)
This prevents references from being defined polymorphically in all contexts - the (abbreviated) canonical example of abuse:
let v = ... $ newIORef undefined in
do writeIORef v ("0" :: [Char])
n <- readIORef v
return (n + 1 :: Int)
...would cause a type error - the type of undefined
is also made monomorphic by the annotated type of newIORef
, resulting in the
type monomo a . IO (IORef a)
for v
, preventing it from being used with both [Char]
and Int
.
Definitions relying on the old behaviour would be modified to use, or replaced by new primitives.
Atravers 00:21, 7 January 2019 (UTC)