Last active
December 18, 2015 23:59
-
-
Save rblaze/5865770 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
[1 of 1] Compiling VV ( test.hs, test.o ) | |
test.hs:17:57: | |
Could not deduce (Storable a0) arising from a use of `sizeOf' | |
from the context (Num a, Storable a) | |
bound by the type signature for | |
loadVector :: (Num a, Storable a) => String -> IO (U.Vector a) | |
at test.hs:11:15-62 | |
The type variable `a0' is ambiguous | |
Possible fix: add a type signature that fixes these type variable(s) | |
Note: there are several potential instances: | |
instance Storable Bool -- Defined in `Foreign.Storable' | |
instance Storable Char -- Defined in `Foreign.Storable' | |
instance Storable Double -- Defined in `Foreign.Storable' | |
...plus 15 others | |
In the second argument of `div', namely `sizeOf (0 :: a)' | |
In the second argument of `U.unsafeFromForeignPtr0', namely | |
`(len `div` sizeOf (0 :: a))' | |
In the second argument of `($)', namely | |
`U.unsafeFromForeignPtr0 ptr (len `div` sizeOf (0 :: a))' | |
test.hs:17:65: | |
Could not deduce (Num a1) arising from the literal `0' | |
from the context (Num a, Storable a) | |
bound by the type signature for | |
loadVector :: (Num a, Storable a) => String -> IO (U.Vector a) | |
at test.hs:11:15-62 | |
Possible fix: | |
add (Num a1) to the context of | |
an expression type signature: a1 | |
or the type signature for | |
loadVector :: (Num a, Storable a) => String -> IO (U.Vector a) | |
In the first argument of `sizeOf', namely `(0 :: a)' | |
In the second argument of `div', namely `sizeOf (0 :: a)' | |
In the second argument of `U.unsafeFromForeignPtr0', namely | |
`(len `div` sizeOf (0 :: a))' |
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 :: (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