Skip to content

Instantly share code, notes, and snippets.

@autotaker
Created April 4, 2016 03:19
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 autotaker/4eb6a528eed4ef665e9bcf1d91441094 to your computer and use it in GitHub Desktop.
Save autotaker/4eb6a528eed4ef665e9bcf1d91441094 to your computer and use it in GitHub Desktop.
{-# LANGUAGE BangPatterns #-}
import qualified Data.Vector as V
{-# NOINLINE check #-}
check :: String -> Int -> IO ()
check testName _ = putStrLn $ testName ++ ": safe!"
{-# NOINLINE test1 #-}
test1 :: V.Vector Int -> IO ()
test1 !v = check "test1" (V.unsafeIndex v 0)
{-# NOINLINE test2 #-}
test2 :: V.Vector Int -> IO ()
test2 !v = do
a <- V.unsafeIndexM v 0
check "test2" a
{-# NOINLINE test3 #-}
test3 :: V.Vector Int -> IO ()
test3 !v = check "test3" $! (V.unsafeIndex v 0)
main :: IO ()
main = do
let v = V.replicate 1 undefined
test1 v
test2 v
test3 v
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment