Create a gist now

Instantly share code, notes, and snippets.

{-# 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