Skip to content

Instantly share code, notes, and snippets.

@qnikst
Created August 19, 2012 19:33
Show Gist options
  • Save qnikst/3397193 to your computer and use it in GitHub Desktop.
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
-- | 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