packages feed

MonadCompose 0.8.1.0 → 0.8.2.0

raw patch · 2 files changed

+25/−25 lines, 2 filesPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

API changes (from Hackage documentation)

- Control.Linear: Foreign :: Foreign
- Control.Linear: Freeable :: Freeable
- Control.Linear: data Foreign
- Control.Linear: data Freeable
- Control.Linear: instance Copyable Focused
- Control.Linear: instance Copyable Foreign
- Control.Linear: instance Weakening (Pointer p Foreign t)
- Control.Linear: newForeign :: Storable t => t -> A () Blank (Pointer p Foreign t)
+ Control.Linear: Linear :: Linear
+ Control.Linear: Nonlinear :: Nonlinear
+ Control.Linear: data Linear
+ Control.Linear: data Nonlinear
+ Control.Linear: instance Splitable Focused
+ Control.Linear: instance Splitable Nonlinear
+ Control.Linear: instance Weakening (Pointer p Nonlinear t)
+ Control.Linear: newNonlinear :: Storable t => t -> A () Blank (Pointer p Nonlinear t)
- Control.Linear: contraction :: Copyable s => A () (Pointer p s t) (Pair (Pointer p s t) (Pointer p s t))
+ Control.Linear: contraction :: A () (Pointer Nonlinear s t) (Pair (Pointer Nonlinear s t) (Pointer Nonlinear s t))
- Control.Linear: focus :: (forall p. A a (Pair (Pointer p Focused t) u) (Pair v St)) -> A a (Pair (Pointer p2 s t) u) (Pair (Pair (Pointer p2 s t) v) St)
+ Control.Linear: focus :: (forall p. A a (Pair (Pointer p Focused t) u) (Pair v St)) -> A a (Pair (Pointer p s t) u) (Pair (Pair (Pointer p s t) v) St)
- Control.Linear: peek' :: Storable t => Fn (Pointer p Freeable t) (Pair (Pointer p Placeholder t) t)
+ Control.Linear: peek' :: Storable t => Fn (Pointer p Linear t) (Pair (Pointer p Placeholder t) t)
- Control.Linear: peek1 :: (Storable t, Copyable s) => A t (Pair (Pointer p s t) St) (Pair (Pointer p s t) St)
+ Control.Linear: peek1 :: Storable t => A t (Pair (Pointer Nonlinear s t) St) (Pair (Pointer Nonlinear s t) St)
- Control.Linear: poke' :: Storable t => Fn (Pair (Pointer p Placeholder t) t) (Pointer p Freeable t)
+ Control.Linear: poke' :: Storable t => Fn (Pair (Pointer p Placeholder t) t) (Pointer p Linear t)
- Control.Linear: split :: (Storable t, Storable u, Copyable s) => A () (Pointer p s (Pair t u)) (Pair (Pointer p s t) (Pointer p s u))
+ Control.Linear: split :: (Storable t, Storable u, Splitable s) => A () (Pointer p s (Pair t u)) (Pair (Pointer p s t) (Pointer p s u))

Files

Control/Linear.hs view
@@ -1,5 +1,5 @@ {-# LANGUAGE Rank2Types, ScopedTypeVariables, MagicHash, UnboxedTuples, FlexibleInstances, GeneralizedNewtypeDeriving, NoMonomorphismRestriction #-}
--- | A linear type-based I/O system a la Clean.
+-- | A linear type-based I/O system a la Clean - including a "safe C" (like Cyclone).
 --
 --   This is an alternative to composing monads - one can decompose them into their
 --   corresponding comonads, with linear operations for manipulating them.
@@ -10,13 +10,13 @@ -- * Basic I/O system
 Exclusive, Semiclosed, Open, Placeholder(Placeholder), open, getStdin, getStdout, getStderr, close, close1, fileSize, setFileSize, eof, seek, tell, char, line, lookahead, contents, putC, putS, random,
 -- * Safe pointer facilities
-Pointer, Freeable(Freeable), Foreign(Foreign), Focused(Focused), Fix(In), fixInj1, fixInj2, Weakening(weakening), contraction, new, free, split, ptrSwap,
+Pointer, Linear(Linear), Nonlinear(Nonlinear), Focused(Focused), Fix(In), fixInj1, fixInj2, Weakening(weakening), contraction, new, free, split, ptrSwap,
 -- ** Focusing
 focus, focusHdl,
 -- ** Strong update
 peek', poke', changeType,
 -- ** Operations on nonlinear data / Weak update
-newForeign, peek1, poke1
+newNonlinear, peek1, poke1
 ) where
 
 import Control.Arrow
@@ -250,35 +250,35 @@ 		p2 <- peekByteOff p 4
 		IO (\s -> (# s, Pointer fp p2 s #)) -- ...so produce one here.
 
--- | Pointers can be freeable, foreign, or focused. There are the following
+-- | Pointers can be linear, nonlinear, or focused. There are the following
 --   tradeoffs:
 --
---   * Freeable pointers support strong update, but can only be split
+--   * Linear pointers support strong update, but can only be split
 --       under focusing.
 --
---   * Foreign pointers can be split, but do not support strong update.
+--   * Nonlinear pointers can be split, but do not support strong update.
 --
 --   Placeholders classify pointers that either point to junk or to data that
 --   is not allowed to be used (to maintain linearity).
-data Freeable = Freeable
+data Linear = Linear
 
 data Focused = Focused
 
-data Foreign = Foreign
+data Nonlinear = Nonlinear
 
 data Placeholder = Placeholder
 
-class Copyable s
+class Splitable s
 
-instance Copyable Focused
+instance Splitable Nonlinear
 
-instance Copyable Foreign
+instance Splitable Focused
 
 {-# NOINLINE dummy #-}
 dummy :: ForeignPtr Blank
 dummy = unsafePerformIO (A.malloc >>= newForeignPtr_)
 
-contraction :: (Copyable s) => A () (Pointer p s t) (Pair (Pointer p s t) (Pointer p s t))
+contraction :: A () (Pointer Nonlinear s t) (Pair (Pointer Nonlinear s t) (Pointer Nonlinear s t))
 contraction = A (\p -> (Pair p p, ()))
 
 class Weakening t where
@@ -287,14 +287,14 @@ instance Weakening (Pointer p Focused t) where
 	weakening = A (\(Pointer _ _ _) -> (Blank, ()))
 
-instance Weakening (Pointer p Foreign t) where
+instance Weakening (Pointer p Nonlinear t) where
 	weakening = A (\(Pointer fp _ world) -> let IO f = touchForeignPtr fp in
 		case f world of (# _, () #) -> (Blank, ()))
 
 instance Weakening (Open p) where
 	weakening = A (\(Open _) -> (Blank, ()))
 
--- | Allocate a new freeable block (containing junk), Use 'poke'' to initialize it.
+-- | Allocate a new linear block (containing junk), Use 'poke'' to initialize it.
 {-# NOINLINE new #-}
 new :: (Storable t) => A () Blank (Pointer p Placeholder t)
 new = A (\Blank -> unsafePerformIO (liftM (\p -> (Pointer dummy p realWorld#, ())) A.malloc))
@@ -307,7 +307,7 @@ 	case f world of (# _, () #) -> (Blank, ()))
 
 -- | Split a pointer to a pair, into a pair of pointers.
-split :: forall t u p s. (Storable t, Storable u, Copyable s) => A () (Pointer p s (Pair t u)) (Pair (Pointer p s t) (Pointer p s u))
+split :: forall t u p s. (Storable t, Storable u, Splitable s) => A () (Pointer p s (Pair t u)) (Pair (Pointer p s t) (Pointer p s u))
 split = A (\(Pointer fp p _) -> (Pair
 	(Pointer fp (frst p) realWorld#)
 	(Pointer fp (secnd p) realWorld#), ()))
@@ -317,10 +317,10 @@ 
 -- | Focusing on a pointer.
 --
---   Temporarily turns a freeable pointer into a focused pointer. I get the freeable
+--   Temporarily turns a linear pointer into a focused pointer. I get the linear
 --   pointer back after all copies have been surrendered (with 'weakening').
 focus :: (forall p. A a (Pair (Pointer p Focused t) u) (Pair v St))
-	-> A a (Pair (Pointer p2 s t) u) (Pair (Pair (Pointer p2 s t) v) St)
+	-> A a (Pair (Pointer p s t) u) (Pair (Pair (Pointer p s t) v) St)
 focus (A f) = A (\(Pair ptr@(Pointer fp p _) x) -> first (\(Pair x st) -> Pair (Pair ptr x) st) (f (Pair (Pointer fp p realWorld#) x))) >>== \x -> updateWorld1 >>== \_ -> rtn x
 
 -- | Focusing on a handle.
@@ -335,11 +335,11 @@ updateWorld1 = manipulate . bimap' updateWorld id . manipulate
 
 -- | Take the data out of a block, making it a placeholder.
-peek' :: (Storable t) => Fn (Pointer p Freeable t) (Pair (Pointer p Placeholder t) t)
+peek' :: (Storable t) => Fn (Pointer p Linear t) (Pair (Pointer p Placeholder t) t)
 peek' = updateWorld1 . lift (\(Pointer fp p st) -> liftM (\x -> (Pair (Pointer fp p st) x, ())) (peek p))
 
 -- | The reverse operation.
-poke' :: (Storable t) => Fn (Pair (Pointer p Placeholder t) t) (Pointer p Freeable t)
+poke' :: (Storable t) => Fn (Pair (Pointer p Placeholder t) t) (Pointer p Linear t)
 poke' = updateWorld . lift (\(Pair (Pointer fp p world) x) -> poke p x >> return (Pointer fp p world, ()))
 
 -- | A placeholder block can change its type.
@@ -350,16 +350,16 @@ 		error "Control.Linear.changeType: value won't fit"
 
 -- Linearity ensures that a program must touch the pointer in order to dispose of it.
--- | Allocate a Foreign pointer.
-{-# NOINLINE newForeign #-}
-newForeign :: (Storable t) => t -> A () Blank (Pointer p Foreign t)
-newForeign x = A (\Blank -> unsafePerformIO $ do
+-- | Allocate a nonlinear pointer.
+{-# NOINLINE newNonlinear #-}
+newNonlinear :: (Storable t) => t -> A () Blank (Pointer p Nonlinear t)
+newNonlinear x = A (\Blank -> unsafePerformIO $ do
 	p <- A.malloc
 	poke p x
 	fp <- newForeignPtr_ p
 	return (Pointer (castForeignPtr fp) p realWorld#, ()))
 
-peek1 :: (Storable t, Copyable s) => A t (Pair (Pointer p s t) St) (Pair (Pointer p s t) St)
+peek1 :: (Storable t) => A t (Pair (Pointer Nonlinear s t) St) (Pair (Pointer Nonlinear s t) St)
 peek1 = lift (\ptr@(Pointer _ p _) -> liftM (\x -> (ptr, x)) $ peek p) >>== \x -> updateWorld >>== \_ -> rtn x
 
 poke1 :: (Storable t) => t -> Fn (Pointer p s t) (Pointer p s t)
MonadCompose.cabal view
@@ -1,5 +1,5 @@ name:                MonadCompose
-version:             0.8.1.0
+version:             0.8.2.0
 synopsis:            Methods for composing monads.
 description:         Methods for composing monads.
   .