Created
April 4, 2016 03:19
-
-
Save autotaker/4eb6a528eed4ef665e9bcf1d91441094 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# 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