Difference between revisions of "Monomorphism by annotation of type variables"
Jump to navigation
Jump to search
(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)...") |
m |
||
Line 22: | Line 22: | ||
Definitions relying on the old behaviour would be modified to use, or replaced by new primitives. |
Definitions relying on the old behaviour would be modified to use, or replaced by new primitives. |
||
− | |||
[[User:Atravers|Atravers]] 00:21, 7 January 2019 (UTC) |
[[User:Atravers|Atravers]] 00:21, 7 January 2019 (UTC) |
Revision as of 01:19, 7 January 2019
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)