Safe Haskell | None |
---|---|
Language | Haskell98 |
A linear type-based I/O system a la Clean.
This is an alternative to composing monads - one can decompose them into their corresponding comonads, with linear operations for manipulating them. (See Kieburtz, http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.46.5169&rep=rep1&type=pdf)
- data St
- data A t u v
- data Blank
- data Pair t u
- type Fn t u = A () (Pair t St) (Pair u St)
- data Open
- data Semiclosed
- data Freeable = Freeable
- data Foreign = Foreign
- data Placeholder = Placeholder
- data Pointer p s t
- (>>==) :: A t2 t t3 -> (t2 -> A t1 t3 v) -> A t1 t v
- rtn :: t -> A t v v
- run :: A a St St -> IO a
- bimap :: A t3 t t2 -> A t4 t1 u -> A (t3, t4) (Pair t t1) (Pair t2 u)
- assoc1 :: A () (Pair (Pair t t1) u) (Pair t (Pair t1 u))
- assoc2 :: A () (Pair t (Pair u1 u)) (Pair (Pair t u1) u)
- drop1 :: A () (Pair Blank v) v
- drop2 :: A () (Pair v Blank) v
- undrop1 :: A () u (Pair Blank u)
- undrop2 :: A () t (Pair t Blank)
- swap :: A () (Pair u t) (Pair t u)
- apply :: A t (Pair (A t t1 v) t1) v
- curry :: A t (Pair t1 u) v -> A () t1 (A t u v)
- distr :: A () (Pair t (Either a a1)) (Either (Pair t a) (Pair t a1))
- void' :: A t1 t v -> A () t v
- bimap' :: A () t u -> A () v w -> A () (Pair t v) (Pair u w)
- open :: FilePath -> IOMode -> A () (Pair Blank St) (Pair Open St)
- getStdin :: A () Blank Open
- getStdout :: A () Blank Open
- getStderr :: A () Blank Open
- close :: A () (Pair Open St) St
- close1 :: A () (Pair Semiclosed St) St
- fileSize :: A Integer (Pair Open St) (Pair Open St)
- setFileSize :: Integer -> A () (Pair Open St) (Pair Open St)
- eof :: A Bool (Pair Open St) (Pair Open St)
- seek :: SeekMode -> Integer -> A () (Pair Open St) (Pair Open St)
- tell :: A Integer (Pair Open St) (Pair Open St)
- char :: A Char (Pair Open St) (Pair Open St)
- line :: A String (Pair Open St) (Pair Open St)
- lookahead :: A Char (Pair Open St) (Pair Open St)
- contents :: A String (Pair Open St) (Pair Semiclosed St)
- putC :: Char -> A () (Pair Open St) (Pair Open St)
- putS :: String -> A () (Pair Open St) (Pair Open St)
- random :: A StdGen Blank Blank
- frst :: (Storable a, Storable b) => Ptr (Pair a b) -> Ptr a
- secnd :: forall a b. (Storable a, Storable b) => Ptr (Pair a b) -> Ptr b
- data Fix f = In (f (Fix f))
- fixInj1 :: Pointer p s (Fix f) -> Pointer p s (f (Fix f))
- fixInj2 :: Pointer p s (f (Fix f)) -> Pointer p s (Fix f)
- newForeign :: A (ForeignPtr t) (Pair (Pointer p Freeable t) St) St
- new :: Storable t => A () Blank (Pointer p Placeholder t)
- get :: Nonlinear t => ForeignPtr t -> A () Blank (Pointer p Foreign t)
- weakening :: A () (Pointer p Foreign t) Blank
- contraction :: A () (Pointer p Foreign t) (Pair (Pointer p Foreign t) (Pointer p Foreign t))
- free :: A () (Pointer p2 Placeholder t) Blank
- focus :: (forall p. A a (Pair (Pointer p Foreign t) u) (Pair v St)) -> A a (Pair (Pointer p2 s t) u) (Pair (Pair (Pointer p2 s t) v) St)
- peek' :: Storable t => Fn (Pointer p Freeable t) (Pair (Pointer p Placeholder t) t)
- poke' :: Storable t => Fn (Pair (Pointer p Placeholder t) t) (Pointer p Freeable t)
- changeType :: forall t u p. (Storable t, Storable u) => A () (Pointer p Placeholder t) (Pointer p Placeholder u)
- peek1 :: (Nonlinear t, Storable t) => A t (Pair (Pointer p s t) St) (Pair (Pointer p s t) St)
- poke1 :: Storable t => t -> Fn (Pointer p2 s t) (Pointer p2 s t)
- split :: forall t u p. (Storable t, Storable u) => A () (Pointer p Foreign (Pair t u)) (Pair (Pointer p Foreign t) (Pointer p Foreign u))
Documentation
Linear computations are arrows over linear data, but monads over nonlinear data.
data Semiclosed Source
Pointers can be freeable or foreign. Freeable pointers are created with new
.
Linearity is enforced for them, so I can do strong update, but the need
to keep track of all pointers means that split
cannot be supported.
Foreign pointers on the other hand can be copied indefinitely since the
garbage collector is keeping track of them.
Freeable pointers can be turned into foreign pointers permanently using
newForeign
, or temporarily by focusing.
Placeholders classify pointers that either point to junk or to data that is not allowed to be used (to maintain linearity).
(>>==) :: A t2 t t3 -> (t2 -> A t1 t3 v) -> A t1 t v infixl 1 Source
Monadic bind (for nonlinear data).
With the Fix constructor, I can build data structures of linear data.
newForeign :: A (ForeignPtr t) (Pair (Pointer p Freeable t) St) St Source
contraction :: A () (Pointer p Foreign t) (Pair (Pointer p Foreign t) (Pointer p Foreign t)) Source
Contraction and weakening are available for pointers created from ForeignPtrs (and pointers I am focusing on).
focus :: (forall p. A a (Pair (Pointer p Foreign t) u) (Pair v St)) -> A a (Pair (Pointer p2 s t) u) (Pair (Pair (Pointer p2 s t) v) St) Source
Focusing on a pointer.
changeType :: forall t u p. (Storable t, Storable u) => A () (Pointer p Placeholder t) (Pointer p Placeholder u) Source