Debian Codegraph @

Foreign/Marshal/Utils/Lifted.hs

raw
1 {-# LANGUAGE CPP #-}
2 {-# LANGUAGE NoImplicitPrelude #-}
3 {-# LANGUAGE FlexibleContexts #-}
4
5 #if __GLASGOW_HASKELL__ >= 710
6 {-# LANGUAGE Safe #-}
7 #elif __GLASGOW_HASKELL__ >= 702
8 {-# LANGUAGE Trustworthy #-}
9 #endif
10
11 {- |
12 Module : Foreign.Marshal.Utils.Lifted
13 Copyright : Bas van Dijk, Anders Kaseorg, Michael Steele
14 License : BSD-style
15
16 Maintainer : Bas van Dijk <[email protected]>
17 Stability : experimental
18 Portability : non-portable (extended exceptions)
19
20 This is a wrapped version of "Foreign.Marshal.Utils" with types generalized
21 from 'IO' to all monads in either 'MonadBase' or 'MonadBaseControl'.
22 -}
23
24 module Foreign.Marshal.Utils.Lifted
25 ( with
26 ) where
27
28 -- from base:
29 import qualified Foreign as F
30 import System.IO ( IO )
31 import Prelude ( (.) )
32
33 -- from monad-control:
34 import Control.Monad.Trans.Control ( MonadBaseControl
35 , liftBaseOp )
36
37 -- |Generalized version of 'F.with'.
38 --
39 -- Note, when the given function throws an exception any monadic side
40 -- effects in @m@ will be discarded.
41 with :: (MonadBaseControl IO m, F.Storable a)
42 => a -- ^ value to be poked
43 -> (F.Ptr a -> m b) -- ^ computation to run
44 -> m b
45 with = liftBaseOp . F.with
46 {-# INLINEABLE with #-}