hmpfr-0.4.4: Haskell binding to the MPFR library

Safe HaskellNone
LanguageHaskell98

Data.Number.MPFR.Internal

Synopsis

Documentation

unsafePerformIO :: IO a -> a #

This is the "back door" into the IO monad, allowing IO computation to be performed at any time. For this to be safe, the IO computation should be free of side effects and independent of its environment.

If the I/O computation wrapped in unsafePerformIO performs side effects, then the relative order in which those side effects take place (relative to the main I/O trunk, or other calls to unsafePerformIO) is indeterminate. Furthermore, when using unsafePerformIO to cause side-effects, you should take the following precautions to ensure the side effects are performed as many times as you expect them to be. Note that these precautions are necessary for GHC, but may not be sufficient, and other compilers may require different precautions:

  • Use {-# NOINLINE foo #-} as a pragma on any function foo that calls unsafePerformIO. If the call is inlined, the I/O may be performed more than once.
  • Use the compiler flag -fno-cse to prevent common sub-expression elimination being performed on the module, which might combine two side effects that were meant to be separate. A good example is using multiple global variables (like test in the example below).
  • Make sure that the either you switch off let-floating (-fno-full-laziness), or that the call to unsafePerformIO cannot float outside a lambda. For example, if you say: f x = unsafePerformIO (newIORef []) you may get only one reference cell shared between all calls to f. Better would be f x = unsafePerformIO (newIORef [x]) because now it can't float outside the lambda.

It is less well known that unsafePerformIO is not type safe. For example:

    test :: IORef [a]
    test = unsafePerformIO $ newIORef []

    main = do
            writeIORef test [42]
            bang <- readIORef test
            print (bang :: [Char])

This program will core dump. This problem with polymorphic references is well known in the ML community, and does not arise with normal monadic use of references. There is no easy way to make it impossible once you use unsafePerformIO. Indeed, it is possible to write coerce :: a -> b with the help of unsafePerformIO. So be careful!

peek :: Storable a => Ptr a -> IO a #

Read a value from the given memory location.

Note that the peek and poke functions might require properly aligned addresses to function correctly. This is architecture dependent; thus, portable code should ensure that when peeking or poking values of some type a, the alignment constraint for a, as given by the function alignment is fulfilled.

data Ptr a :: * -> * #

A value of type Ptr a represents a pointer to an object, or an array of objects, which may be marshalled to or from Haskell values of type a.

The type a will often be an instance of class Storable which provides the marshalling operations. However this is not essential, and you can provide your own operations to access the pointer. For example you might write small foreign functions to get or set the fields of a C struct.

Instances

Generic1 k (URec k (Ptr ())) 

Associated Types

type Rep1 (URec k (Ptr ())) (f :: URec k (Ptr ()) -> *) :: k -> * #

Methods

from1 :: f a -> Rep1 (URec k (Ptr ())) f a #

to1 :: Rep1 (URec k (Ptr ())) f a -> f a #

Eq (Ptr a) 

Methods

(==) :: Ptr a -> Ptr a -> Bool #

(/=) :: Ptr a -> Ptr a -> Bool #

Ord (Ptr a) 

Methods

compare :: Ptr a -> Ptr a -> Ordering #

(<) :: Ptr a -> Ptr a -> Bool #

(<=) :: Ptr a -> Ptr a -> Bool #

(>) :: Ptr a -> Ptr a -> Bool #

(>=) :: Ptr a -> Ptr a -> Bool #

max :: Ptr a -> Ptr a -> Ptr a #

min :: Ptr a -> Ptr a -> Ptr a #

Show (Ptr a)

Since: 2.1

Methods

showsPrec :: Int -> Ptr a -> ShowS #

show :: Ptr a -> String #

showList :: [Ptr a] -> ShowS #

Storable (Ptr a)

Since: 2.1

Methods

sizeOf :: Ptr a -> Int #

alignment :: Ptr a -> Int #

peekElemOff :: Ptr (Ptr a) -> Int -> IO (Ptr a) #

pokeElemOff :: Ptr (Ptr a) -> Int -> Ptr a -> IO () #

peekByteOff :: Ptr b -> Int -> IO (Ptr a) #

pokeByteOff :: Ptr b -> Int -> Ptr a -> IO () #

peek :: Ptr (Ptr a) -> IO (Ptr a) #

poke :: Ptr (Ptr a) -> Ptr a -> IO () #

Functor (URec * (Ptr ())) 

Methods

fmap :: (a -> b) -> URec * (Ptr ()) a -> URec * (Ptr ()) b #

(<$) :: a -> URec * (Ptr ()) b -> URec * (Ptr ()) a #

Foldable (URec * (Ptr ())) 

Methods

fold :: Monoid m => URec * (Ptr ()) m -> m #

foldMap :: Monoid m => (a -> m) -> URec * (Ptr ()) a -> m #

foldr :: (a -> b -> b) -> b -> URec * (Ptr ()) a -> b #

foldr' :: (a -> b -> b) -> b -> URec * (Ptr ()) a -> b #

foldl :: (b -> a -> b) -> b -> URec * (Ptr ()) a -> b #

foldl' :: (b -> a -> b) -> b -> URec * (Ptr ()) a -> b #

foldr1 :: (a -> a -> a) -> URec * (Ptr ()) a -> a #

foldl1 :: (a -> a -> a) -> URec * (Ptr ()) a -> a #

toList :: URec * (Ptr ()) a -> [a] #

null :: URec * (Ptr ()) a -> Bool #

length :: URec * (Ptr ()) a -> Int #

elem :: Eq a => a -> URec * (Ptr ()) a -> Bool #

maximum :: Ord a => URec * (Ptr ()) a -> a #

minimum :: Ord a => URec * (Ptr ()) a -> a #

sum :: Num a => URec * (Ptr ()) a -> a #

product :: Num a => URec * (Ptr ()) a -> a #

Eq (URec k (Ptr ()) p) 

Methods

(==) :: URec k (Ptr ()) p -> URec k (Ptr ()) p -> Bool #

(/=) :: URec k (Ptr ()) p -> URec k (Ptr ()) p -> Bool #

Ord (URec k (Ptr ()) p) 

Methods

compare :: URec k (Ptr ()) p -> URec k (Ptr ()) p -> Ordering #

(<) :: URec k (Ptr ()) p -> URec k (Ptr ()) p -> Bool #

(<=) :: URec k (Ptr ()) p -> URec k (Ptr ()) p -> Bool #

(>) :: URec k (Ptr ()) p -> URec k (Ptr ()) p -> Bool #

(>=) :: URec k (Ptr ()) p -> URec k (Ptr ()) p -> Bool #

max :: URec k (Ptr ()) p -> URec k (Ptr ()) p -> URec k (Ptr ()) p #

min :: URec k (Ptr ()) p -> URec k (Ptr ()) p -> URec k (Ptr ()) p #

Generic (URec k (Ptr ()) p) 

Associated Types

type Rep (URec k (Ptr ()) p) :: * -> * #

Methods

from :: URec k (Ptr ()) p -> Rep (URec k (Ptr ()) p) x #

to :: Rep (URec k (Ptr ()) p) x -> URec k (Ptr ()) p #

data URec k (Ptr ())

Used for marking occurrences of Addr#

Since: 4.9.0.0

data URec k (Ptr ()) = UAddr {}
type Rep1 k (URec k (Ptr ())) 
type Rep1 k (URec k (Ptr ())) = D1 k (MetaData "URec" "GHC.Generics" "base" False) (C1 k (MetaCons "UAddr" PrefixI True) (S1 k (MetaSel (Just Symbol "uAddr#") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (UAddr k)))
type Rep (URec k (Ptr ()) p) 
type Rep (URec k (Ptr ()) p) = D1 * (MetaData "URec" "GHC.Generics" "base" False) (C1 * (MetaCons "UAddr" PrefixI True) (S1 * (MetaSel (Just Symbol "uAddr#") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (UAddr *)))

nullPtr :: Ptr a #

The constant nullPtr contains a distinguished value of Ptr that is not associated with a valid memory location.

mallocForeignPtrBytes :: Int -> IO (ForeignPtr a) #

This function is similar to mallocForeignPtr, except that the size of the memory required is given explicitly as a number of bytes.

with :: Storable a => a -> (Ptr a -> IO b) -> IO b #

with val f executes the computation f, passing as argument a pointer to a temporarily allocated block of memory into which val has been marshalled (the combination of alloca and poke).

The memory is freed when f terminates (either normally or via an exception), so the pointer passed to f must not be used after this.

withForeignPtr :: ForeignPtr a -> (Ptr a -> IO b) -> IO b #

This is a way to look at the pointer living inside a foreign object. This function takes a function which is applied to that pointer. The resulting IO action is then executed. The foreign object is kept alive at least during the whole action, even if it is not used directly inside. Note that it is not safe to return the pointer from the action and use it after the action completes. All uses of the pointer should be inside the withForeignPtr bracket. The reason for this unsafeness is the same as for unsafeForeignPtrToPtr below: the finalizer may run earlier than expected, because the compiler can only track usage of the ForeignPtr object, not a Ptr object made from it.

This function is normally used for marshalling data to or from the object pointed to by the ForeignPtr, using the operations from the Storable class.

data CInt :: * #

Haskell type representing the C int type.

Instances

Bounded CInt 
Enum CInt 

Methods

succ :: CInt -> CInt #

pred :: CInt -> CInt #

toEnum :: Int -> CInt #

fromEnum :: CInt -> Int #

enumFrom :: CInt -> [CInt] #

enumFromThen :: CInt -> CInt -> [CInt] #

enumFromTo :: CInt -> CInt -> [CInt] #

enumFromThenTo :: CInt -> CInt -> CInt -> [CInt] #

Eq CInt 

Methods

(==) :: CInt -> CInt -> Bool #

(/=) :: CInt -> CInt -> Bool #

Integral CInt 

Methods

quot :: CInt -> CInt -> CInt #

rem :: CInt -> CInt -> CInt #

div :: CInt -> CInt -> CInt #

mod :: CInt -> CInt -> CInt #

quotRem :: CInt -> CInt -> (CInt, CInt) #

divMod :: CInt -> CInt -> (CInt, CInt) #

toInteger :: CInt -> Integer #

Num CInt 

Methods

(+) :: CInt -> CInt -> CInt #

(-) :: CInt -> CInt -> CInt #

(*) :: CInt -> CInt -> CInt #

negate :: CInt -> CInt #

abs :: CInt -> CInt #

signum :: CInt -> CInt #

fromInteger :: Integer -> CInt #

Ord CInt 

Methods

compare :: CInt -> CInt -> Ordering #

(<) :: CInt -> CInt -> Bool #

(<=) :: CInt -> CInt -> Bool #

(>) :: CInt -> CInt -> Bool #

(>=) :: CInt -> CInt -> Bool #

max :: CInt -> CInt -> CInt #

min :: CInt -> CInt -> CInt #

Read CInt 
Real CInt 

Methods

toRational :: CInt -> Rational #

Show CInt 

Methods

showsPrec :: Int -> CInt -> ShowS #

show :: CInt -> String #

showList :: [CInt] -> ShowS #

Storable CInt 

Methods

sizeOf :: CInt -> Int #

alignment :: CInt -> Int #

peekElemOff :: Ptr CInt -> Int -> IO CInt #

pokeElemOff :: Ptr CInt -> Int -> CInt -> IO () #

peekByteOff :: Ptr b -> Int -> IO CInt #

pokeByteOff :: Ptr b -> Int -> CInt -> IO () #

peek :: Ptr CInt -> IO CInt #

poke :: Ptr CInt -> CInt -> IO () #

Bits CInt 
FiniteBits CInt 

data CLong :: * #

Haskell type representing the C long type.

Instances

Bounded CLong 
Enum CLong 
Eq CLong 

Methods

(==) :: CLong -> CLong -> Bool #

(/=) :: CLong -> CLong -> Bool #

Integral CLong 
Num CLong 
Ord CLong 

Methods

compare :: CLong -> CLong -> Ordering #

(<) :: CLong -> CLong -> Bool #

(<=) :: CLong -> CLong -> Bool #

(>) :: CLong -> CLong -> Bool #

(>=) :: CLong -> CLong -> Bool #

max :: CLong -> CLong -> CLong #

min :: CLong -> CLong -> CLong #

Read CLong 
Real CLong 

Methods

toRational :: CLong -> Rational #

Show CLong 

Methods

showsPrec :: Int -> CLong -> ShowS #

show :: CLong -> String #

showList :: [CLong] -> ShowS #

Storable CLong 

Methods

sizeOf :: CLong -> Int #

alignment :: CLong -> Int #

peekElemOff :: Ptr CLong -> Int -> IO CLong #

pokeElemOff :: Ptr CLong -> Int -> CLong -> IO () #

peekByteOff :: Ptr b -> Int -> IO CLong #

pokeByteOff :: Ptr b -> Int -> CLong -> IO () #

peek :: Ptr CLong -> IO CLong #

poke :: Ptr CLong -> CLong -> IO () #

Bits CLong 
FiniteBits CLong 

data CULong :: * #

Haskell type representing the C unsigned long type.

Instances

Bounded CULong 
Enum CULong 
Eq CULong 

Methods

(==) :: CULong -> CULong -> Bool #

(/=) :: CULong -> CULong -> Bool #

Integral CULong 
Num CULong 
Ord CULong 
Read CULong 
Real CULong 
Show CULong 
Storable CULong 
Bits CULong 
FiniteBits CULong 

withCString :: String -> (CString -> IO a) -> IO a #

Marshal a Haskell string into a NUL terminated C string using temporary storage.

  • the Haskell string may not contain any NUL characters
  • the memory is freed when the subcomputation terminates (either normally or via an exception), so the pointer to the temporary storage must not be used after this.

peekCString :: CString -> IO String #

Marshal a NUL terminated C string into a Haskell string.

alloca :: Storable a => (Ptr a -> IO b) -> IO b #

alloca f executes the computation f, passing as argument a pointer to a temporarily allocated block of memory sufficient to hold values of type a.

The memory is freed when f terminates (either normally or via an exception), so the pointer passed to f must not be used after this.

peekArray :: Storable a => Int -> Ptr a -> IO [a] #

Convert an array of given length into a Haskell list. The implementation is tail-recursive and so uses constant stack space.

shiftL :: Bits a => a -> Int -> a infixl 8 #

Shift the argument left by the specified number of bits (which must be non-negative).

An instance can define either this and shiftR or the unified shift, depending on which is more convenient for the type in question.

data Word :: * #

A Word is an unsigned integral type, with the same size as Int.

Instances

Bounded Word

Since: 2.1

Enum Word

Since: 2.1

Methods

succ :: Word -> Word #

pred :: Word -> Word #

toEnum :: Int -> Word #

fromEnum :: Word -> Int #

enumFrom :: Word -> [Word] #

enumFromThen :: Word -> Word -> [Word] #

enumFromTo :: Word -> Word -> [Word] #

enumFromThenTo :: Word -> Word -> Word -> [Word] #

Eq Word 

Methods

(==) :: Word -> Word -> Bool #

(/=) :: Word -> Word -> Bool #

Integral Word

Since: 2.1

Methods

quot :: Word -> Word -> Word #

rem :: Word -> Word -> Word #

div :: Word -> Word -> Word #

mod :: Word -> Word -> Word #

quotRem :: Word -> Word -> (Word, Word) #

divMod :: Word -> Word -> (Word, Word) #

toInteger :: Word -> Integer #

Num Word

Since: 2.1

Methods

(+) :: Word -> Word -> Word #

(-) :: Word -> Word -> Word #

(*) :: Word -> Word -> Word #

negate :: Word -> Word #

abs :: Word -> Word #

signum :: Word -> Word #

fromInteger :: Integer -> Word #

Ord Word 

Methods

compare :: Word -> Word -> Ordering #

(<) :: Word -> Word -> Bool #

(<=) :: Word -> Word -> Bool #

(>) :: Word -> Word -> Bool #

(>=) :: Word -> Word -> Bool #

max :: Word -> Word -> Word #

min :: Word -> Word -> Word #

Read Word

Since: 4.5.0.0

Real Word

Since: 2.1

Methods

toRational :: Word -> Rational #

Show Word

Since: 2.1

Methods

showsPrec :: Int -> Word -> ShowS #

show :: Word -> String #

showList :: [Word] -> ShowS #

Storable Word

Since: 2.1

Methods

sizeOf :: Word -> Int #

alignment :: Word -> Int #

peekElemOff :: Ptr Word -> Int -> IO Word #

pokeElemOff :: Ptr Word -> Int -> Word -> IO () #

peekByteOff :: Ptr b -> Int -> IO Word #

pokeByteOff :: Ptr b -> Int -> Word -> IO () #

peek :: Ptr Word -> IO Word #

poke :: Ptr Word -> Word -> IO () #

Bits Word

Since: 2.1

FiniteBits Word

Since: 4.6.0.0

Generic1 k (URec k Word) 

Associated Types

type Rep1 (URec k Word) (f :: URec k Word -> *) :: k -> * #

Methods

from1 :: f a -> Rep1 (URec k Word) f a #

to1 :: Rep1 (URec k Word) f a -> f a #

Functor (URec * Word) 

Methods

fmap :: (a -> b) -> URec * Word a -> URec * Word b #

(<$) :: a -> URec * Word b -> URec * Word a #

Foldable (URec * Word) 

Methods

fold :: Monoid m => URec * Word m -> m #

foldMap :: Monoid m => (a -> m) -> URec * Word a -> m #

foldr :: (a -> b -> b) -> b -> URec * Word a -> b #

foldr' :: (a -> b -> b) -> b -> URec * Word a -> b #

foldl :: (b -> a -> b) -> b -> URec * Word a -> b #

foldl' :: (b -> a -> b) -> b -> URec * Word a -> b #

foldr1 :: (a -> a -> a) -> URec * Word a -> a #

foldl1 :: (a -> a -> a) -> URec * Word a -> a #

toList :: URec * Word a -> [a] #

null :: URec * Word a -> Bool #

length :: URec * Word a -> Int #

elem :: Eq a => a -> URec * Word a -> Bool #

maximum :: Ord a => URec * Word a -> a #

minimum :: Ord a => URec * Word a -> a #

sum :: Num a => URec * Word a -> a #

product :: Num a => URec * Word a -> a #

Eq (URec k Word p) 

Methods

(==) :: URec k Word p -> URec k Word p -> Bool #

(/=) :: URec k Word p -> URec k Word p -> Bool #

Ord (URec k Word p) 

Methods

compare :: URec k Word p -> URec k Word p -> Ordering #

(<) :: URec k Word p -> URec k Word p -> Bool #

(<=) :: URec k Word p -> URec k Word p -> Bool #

(>) :: URec k Word p -> URec k Word p -> Bool #

(>=) :: URec k Word p -> URec k Word p -> Bool #

max :: URec k Word p -> URec k Word p -> URec k Word p #

min :: URec k Word p -> URec k Word p -> URec k Word p #

Show (URec k Word p) 

Methods

showsPrec :: Int -> URec k Word p -> ShowS #

show :: URec k Word p -> String #

showList :: [URec k Word p] -> ShowS #

Generic (URec k Word p) 

Associated Types

type Rep (URec k Word p) :: * -> * #

Methods

from :: URec k Word p -> Rep (URec k Word p) x #

to :: Rep (URec k Word p) x -> URec k Word p #

data URec k Word

Used for marking occurrences of Word#

Since: 4.9.0.0

data URec k Word = UWord {}
type Rep1 k (URec k Word) 
type Rep1 k (URec k Word) = D1 k (MetaData "URec" "GHC.Generics" "base" False) (C1 k (MetaCons "UWord" PrefixI True) (S1 k (MetaSel (Just Symbol "uWord#") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (UWord k)))
type Rep (URec k Word p) 
type Rep (URec k Word p) = D1 * (MetaData "URec" "GHC.Generics" "base" False) (C1 * (MetaCons "UWord" PrefixI True) (S1 * (MetaSel (Just Symbol "uWord#") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (UWord *)))