File: Unsafe.hs

package info (click to toggle)
haskell-abstract-par 0.3.3-13
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 64 kB
  • sloc: haskell: 55; makefile: 2
file content (36 lines) | stat: -rw-r--r-- 1,217 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
{-# LANGUAGE MultiParamTypeClasses, FunctionalDependencies #-}
-- TODO: ADD Unsafe

-- | Unsafe operations.  NOT part of "Safe Haskell".
-- 
-- These are "unsafe" (in the normal, Haskell sense) when used with a
-- "runPar" of type `Par a -> a`.  If used with a `runParIO` that
-- stays in the IO monad, then they are simply dangerous.
-- 
-- For the purposes of Safe Haskell, any module that imports this
-- module becomes untrustworthy.

module Control.Monad.Par.Unsafe 
  (
   ParUnsafe(..)
  ) 
where

-- import Control.Monad.Par.Class

-- | The class of Par monads that provide unsafe functionality.
class ParUnsafe iv p | p -> iv where 
  -- | Peek at the current contents of an 'IVar' in a nonblocking way.
  unsafePeek   :: iv a -> p (Maybe a)

  -- | Attempt to put a value into an 'IVar'.  If successful, return the
  --   value put.  If something is already there, return it instead.
  unsafeTryPut :: iv a -> a -> p a

  -- | Lift an 'IO' operation into the Par monad.
  unsafeParIO  :: IO a -> p a

-- Aside:
-- If the need ever arises we could also consider unsafeMultiplePut that
-- would be able to change the current value of an IVar.  It could
-- cause big problems in the distributed case, however.