Created
August 19, 2012 19:33
-
-
Save qnikst/3397193 to your computer and use it in GitHub Desktop.
how to make a function that is based on it's return type
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
-- | how to make a function that is based on its return type? | |
class (Storable a) => P a where | |
data Ps a | |
pStorageType :: [a] -> StorageType | |
wP :: [a] -> (Ptr a -> IO b) -> IO b | |
wP xs f = V.unsafeWith (V.fromList xs) f | |
export:: (MonadIO m, Pixel a) => PMagickWand -> Int -> m [a] | |
exportImagePixels len = exportArray len ffiFunction undefined | |
where | |
exportArray :: (Pixel a) => Int -> (StorageType -> Ptr () -> IO b) -> [a] -> IO [a] | |
exportArray s f hack = allocaArray s (\q -> f storage (castPtr q) >> peekArray s q) | |
where storage = pStorageType hack |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment