Monomorphism by annotation of type variables
Revision as of 00:25, 7 January 2019 by Atravers (talk | contribs) (Created page with "Category:Proposals Introduce the reserved word <code>monomo</code> for rendering type variables monomorphic: <haskell> newIORef :: monomo a . a -> IO (IORef a)...")
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)