Skip to content

Instantly share code, notes, and snippets.

@maoe
Created August 26, 2011 10:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maoe/1173157 to your computer and use it in GitHub Desktop.
Save maoe/1173157 to your computer and use it in GitHub Desktop.
MonoLocalBindsの影響
{-# LANGUAGE MonoLocalBinds, ScopedTypeVariables #-}
module MonoLocalBinds where
import Control.Monad.ST
import Data.STRef
f :: forall a. a -> ((a, Char), (a, Bool))
f x = (g 'v', g True)
where
g :: b -> (a, b) -- コメントアウトするとgはgeneralizeされない
g y = (x, y)
foo :: forall a. Bool -> a -> a -> a
foo b x y = runST $ do { r <- newSTRef x; fill r; readSTRef r }
where
fill :: STRef s a -> ST s () -- コメントアウトするとfillはgeneralizeされない
fill r = case b of
True -> return ()
False -> writeSTRef r y
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment