Monomorphism by annotation of type variables

From HaskellWiki
Revision as of 01:19, 7 January 2019 by Atravers (talk | contribs)
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.


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)