Monomorphism by annotation of type variables

From HaskellWiki
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)...")

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, 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)