-
-
Save s9gf4ult/5865851 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
14:51 razor@localhost /home/razor % ghc yoba.hs | |
[1 of 1] Compiling VV ( yoba.hs, yoba.o ) |
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 ScopedTypeVariables #-} | |
module VV where | |
import Control.Monad | |
import Foreign.ForeignPtr.Safe | |
import Foreign.Storable | |
import System.IO | |
import qualified Data.Vector.Storable as U | |
loadVector :: forall a. (Num a, Storable a) => String -> IO (U.Vector a) | |
loadVector name = | |
withFile name ReadMode $ \h -> do | |
len <- liftM fromIntegral $ hFileSize h | |
ptr <- mallocForeignPtrBytes len | |
_ <- withForeignPtr ptr $ \p -> hGetBuf h p len | |
return $ U.unsafeFromForeignPtr0 ptr (len `div` sizeOf (0 :: a) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment