oi 0.3.1 → 0.4.0
raw patch · 12 files changed
+160/−49 lines, 12 filesdep +oidep −SafeSemaphorenew-component:exe:oi-catsnew-component:exe:oi-cats2new-component:exe:oi-echonew-component:exe:oi-morecnew-component:exe:oi-recdircsnew-component:exe:oi-talkPVP ok
version bump matches the API change (PVP)
Dependencies added: oi
Dependencies removed: SafeSemaphore
API changes (from Hackage documentation)
- Data.OI.Internal: errmsg :: IOResult a -> String
- Data.OI.Internal: instance Comonad OI
- Data.OI.Internal: instance Functor IOResult
- Data.OI.Internal: instance Functor OI
- Data.OI.Internal: instance Monad OI
- Data.OI.Internal: instance Show a => Show (IOResult a)
- Data.OI.Internal: result :: IOResult a -> a
- Data.OI.Resource: instance Show a => Show (Resource a)
- Data.OI.Resource: release :: Resource a -> ()
- Data.OI.Resource: stream :: Resource a -> [IOResult a]
+ Data.OI.Internal: [errmsg] :: IOResult a -> String
+ Data.OI.Internal: [result] :: IOResult a -> a
+ Data.OI.Internal: instance Control.Comonad.Comonad Data.OI.Internal.OI
+ Data.OI.Internal: instance GHC.Base.Applicative Data.OI.Internal.OI
+ Data.OI.Internal: instance GHC.Base.Functor Data.OI.Internal.IOResult
+ Data.OI.Internal: instance GHC.Base.Functor Data.OI.Internal.OI
+ Data.OI.Internal: instance GHC.Base.Monad Data.OI.Internal.OI
+ Data.OI.Internal: instance GHC.Show.Show a => GHC.Show.Show (Data.OI.Internal.IOResult a)
+ Data.OI.Resource: [release] :: Resource a -> ()
+ Data.OI.Resource: [stream] :: Resource a -> [IOResult a]
+ Data.OI.Resource: instance GHC.Show.Show a => GHC.Show.Show (Data.OI.Resource.Resource a)
Files
- LICENSE +1/−1
- oi.cabal +58/−14
- sample/Makefile +0/−24
- src/Data/OI.hs +1/−1
- src/Data/OI/Combinator.hs +1/−1
- src/Data/OI/Force.hs +1/−1
- src/Data/OI/IFun.hs +1/−1
- src/Data/OI/IO.hs +1/−1
- src/Data/OI/Internal.hs +9/−2
- src/Data/OI/Merge.hs +78/−1
- src/Data/OI/Resource.hs +1/−1
- src/Data/OI/System.hs +8/−1
LICENSE view
@@ -1,4 +1,4 @@-Copyright (c) 2011, Nobuo Yamashita+Copyright (c) 2011-2016, Nobuo Yamashita All rights reserved. Redistribution and use in source and binary forms, with or without
oi.cabal view
@@ -1,5 +1,5 @@ Name: oi-Version: 0.3.1+Version: 0.4.0 Category: Data Synopsis: Library for purely functional lazy interactions with the outer world. Description: This package implements a data structure and operations on it for writing interactive program with no imperative flavor of IO monads.@@ -15,23 +15,67 @@ Cabal-Version: >= 1.14 Data-dir: sample-Data-files: Makefile cats.hs cats2.hs echo.hs morec.hs recdircs.hs talk.hs Library Default-Language: Haskell2010 Hs-Source-Dirs: src/- Build-Depends: base >= 4.5 && < 5, parallel, comonad >= 3, filepath, directory, SafeSemaphore- GHC-Options: -Wall -O0+ Build-Depends: base >= 4.5 && < 5, parallel, comonad >= 3, filepath, directory+ GHC-Options: -O0 -fcase-merge -fcse -fdo-eta-reduction -fenable-rewrite-rules -ffloat-in -ffull-laziness -fspecialise -fstrictness Exposed-modules: Data.OI- ,Data.OI.Internal- ,Data.OI.Combinator- ,Data.OI.Force- ,Data.OI.IFun- ,Data.OI.IO- ,Data.OI.Merge- ,Data.OI.Resource- ,Data.OI.System+ , Data.OI.Internal+ , Data.OI.Combinator+ , Data.OI.Force+ , Data.OI.IFun+ , Data.OI.IO+ , Data.OI.Merge+ , Data.OI.Resource+ , Data.OI.System +Executable oi-cats+ Hs-Source-Dirs: sample/+ Main-Is: cats.hs+ Build-Depends: base >= 4.5 && < 5+ , oi+ Default-Language: Haskell2010+ +Executable oi-cats2+ Hs-Source-Dirs: sample/+ Main-Is: cats2.hs+ Build-Depends: base >= 4.5 && < 5+ , oi+ Default-Language: Haskell2010+ +Executable oi-echo+ Hs-Source-Dirs: sample/+ Main-Is: echo.hs+ Build-Depends: base >= 4.5 && < 5+ , oi+ Default-Language: Haskell2010+ +Executable oi-morec+ Hs-Source-Dirs: sample/+ Main-Is: morec.hs+ Build-Depends: base >= 4.5 && < 5+ , oi+ Default-Language: Haskell2010+ +Executable oi-recdircs+ Hs-Source-Dirs: sample/+ Main-Is: recdircs.hs+ Build-Depends: base >= 4.5 && < 5+ , directory+ , filepath+ , oi+ Default-Language: Haskell2010+ +Executable oi-talk+ Hs-Source-Dirs: sample/+ Main-Is: talk.hs+ Build-Depends: base >= 4.5 && < 5+ , parallel+ , oi+ Default-Language: Haskell2010+ Source-Repository head- type: darcs- location: http://darcs.sampou.org/oi/+ type: git+ location: https://github.com/nobsun/oi
− sample/Makefile
@@ -1,24 +0,0 @@-EXECS = echo recdircs talk cats cats2 morec--all : $(EXECS)--echo : echo.hs- ghc --make -O0 -threaded $< -o $@--recdircs : recdircs.hs- ghc --make -O0 -threaded $< -o $@--talk : talk.hs- ghc --make -O0 -threaded $< -o $@--cats : cats.hs- ghc --make -O0 -threaded $< -o $@--cats2 : cats2.hs- ghc --make -O0 -threaded $< -o $@--morec : morec.hs- ghc --make -O0 -threaded $< -o $@--clean :- -rm $(EXECS) *.hi *.o *~ core
src/Data/OI.hs view
@@ -1,6 +1,6 @@ -- | -- Module : Data.OI--- Copyright : (c) Nobuo Yamashita 2011-2012+-- Copyright : (c) Nobuo Yamashita 2011-2016 -- License : BSD3 -- Author : Nobuo Yamashita -- Maintainer : nobsun@sampou.org
src/Data/OI/Combinator.hs view
@@ -1,6 +1,6 @@ -- | -- Module : Data.OI.Combinator--- Copyright : (c) Nobuo Yamashita 2011-2012+-- Copyright : (c) Nobuo Yamashita 2011-2016 -- License : BSD3 -- Author : Nobuo Yamashita -- Maintainer : nobsun@sampou.org
src/Data/OI/Force.hs view
@@ -1,6 +1,6 @@ -- | -- Module : Data.OI.Force--- Copyright : (c) Nobuo Yamashita 2012+-- Copyright : (c) Nobuo Yamashita 2012-2016 -- License : BSD3 -- Author : Nobuo Yamashita -- Maintainer : nobsun@sampou.org
src/Data/OI/IFun.hs view
@@ -3,7 +3,7 @@ #-} -- | -- Module : Data.OI.IFun--- Copyright : (c) Nobuo Yamashita 2012+-- Copyright : (c) Nobuo Yamashita 2012-2016 -- License : BSD3 -- Author : Nobuo Yamashita -- Maintainer : nobsun@sampou.org
src/Data/OI/IO.hs view
@@ -1,7 +1,7 @@ {-# LANGUAGE TypeOperators #-} -- | -- Module : Data.OI.IO--- Copyright : (c) Nobuo Yamashita 2011-2012+-- Copyright : (c) Nobuo Yamashita 2011-2016 -- License : BSD3 -- Author : Nobuo Yamashita -- Maintainer : nobsun@sampou.org
src/Data/OI/Internal.hs view
@@ -6,7 +6,7 @@ {-# OPTIONS_GHC -fno-cse #-} -- | -- Module : Data.OI.Base--- Copyright : (c) Nobuo Yamashita 2011-2012+-- Copyright : (c) Nobuo Yamashita 2011-2016 -- License : BSD3 -- Author : Nobuo Yamashita -- Maintainer : nobsun@sampou.org@@ -41,7 +41,7 @@ ) where -import Control.Applicative+-- import Control.Applicative -- import Control.Category import Control.Comonad import Control.Exception@@ -69,6 +69,10 @@ instance Functor OI where fmap f = (##) . f . (??) +instance Applicative OI where+ pure = (##)+ f <*> g = ((f ??) (g ??) ##)+ instance Monad OI where return = (##) (>>=) = flip ($) . (??)@@ -254,12 +258,15 @@ -- Unsafe primitive +{-# NOINLINE unsafeNew #-} unsafeNew :: a -> LeftValueOf a unsafeNew _ = unsafePerformIO newEmptyMVar +{-# NOINLINE unsafeDeref #-} unsafeDeref :: MVar a -> a unsafeDeref = unsafePerformIO . readMVar +{-# NOINLINE unsafePut #-} unsafePut :: a -> MVar a -> a unsafePut x v = unsafePerformIO $ do { s <- tryPutMVar v x
src/Data/OI/Merge.hs view
@@ -1,4 +1,12 @@ {-# LANGUAGE TypeOperators #-}+-- |+-- Module : Data.OI.Merge+-- Copyright : (c) Nobuo Yamashita 2011-2016+-- License : BSD3+-- Author : Nobuo Yamashita+-- Maintainer : nobsun@sampou.org+-- Stability : experimental+-- module Data.OI.Merge ( -- * merge list mergeOI@@ -9,7 +17,6 @@ import Control.Concurrent (forkIO) import Control.Concurrent.MVar (MVar,newEmptyMVar,newMVar,takeMVar,putMVar)-import Control.Concurrent.SSem (SSem,new,signal,wait) import System.IO.Unsafe (unsafeInterleaveIO) mergeOI :: [a] -> [a] -> [a] :-> [a]@@ -18,6 +25,75 @@ nmergeOI :: [[a]] -> [a] :-> [a] nmergeOI = iooi . nmergeIO ++mergeIO :: [a] -> [a] -> IO [a]+nmergeIO :: [[a]] -> IO [a]++-- $merge+-- The 'mergeIO' and 'nmergeIO' functions fork one thread for each+-- input list that concurrently evaluates that list; the results are+-- merged into a single output list. ++mergeIO ls rs+ = newEmptyMVar >>= \ tail_node ->+ newMVar tail_node >>= \ tail_list ->+ newMVar () >>= \ e ->+ newMVar 2 >>= \ branches_running ->+ let+ buff = (tail_list,e)+ in+ forkIO (suckIO branches_running buff ls) >>+ forkIO (suckIO branches_running buff rs) >>+ takeMVar tail_node >>= \ val ->+ putMVar e () >>+ return val++nmergeIO lss+ = let+ len = length lss+ in+ newEmptyMVar >>= \ tail_node ->+ newMVar tail_node >>= \ tail_list ->+ newMVar () >>= \ e ->+ newMVar len >>= \ branches_running ->+ let+ buff = (tail_list,e)+ in+ mapM_ (\ x -> forkIO (suckIO branches_running buff x)) lss >>+ takeMVar tail_node >>= \ val ->+ putMVar e () >>+ return val++type Buffer a+ = (MVar (MVar [a]), MVar ())++suckIO :: MVar Int -> Buffer a -> [a] -> IO ()+suckIO branches_running buff@(tail_list,e) vs+ = case vs of+ [] -> takeMVar branches_running >>= \ val ->+ if val == 1 then+ takeMVar tail_list >>= \ node ->+ putMVar node [] >>+ putMVar tail_list node+ else+ putMVar branches_running (val-1)+ (x:xs) ->+ takeMVar e >>= \ () ->+ takeMVar tail_list >>= \ node ->+ newEmptyMVar >>= \ next_node ->+ unsafeInterleaveIO (+ takeMVar next_node >>= \ y ->+ putMVar e () >>+ return y) >>= \ next_node_val ->+ putMVar node (x:next_node_val) >>+ putMVar tail_list next_node >>+ suckIO branches_running buff xs++++++{- -- The origin of following codes came from Control.Concurrent module. -- The original codes using Control.Concurrent.QSem were deprecated. -- The following codes are made by modifying the original code to use@@ -85,3 +161,4 @@ putMVar node (x:next_node_val) >> putMVar tail_list next_node >> suckIO branches_running buff xs+-}
src/Data/OI/Resource.hs view
@@ -1,7 +1,7 @@ {-# LANGUAGE TypeOperators #-} -- | -- Module : Data.OI.Resource--- Copyright : (c) Nobuo Yamashita 2011-2012+-- Copyright : (c) Nobuo Yamashita 2011-2016 -- License : BSD3 -- Author : Nobuo Yamashita -- Maintainer : nobsun@sampou.org
src/Data/OI/System.hs view
@@ -1,6 +1,13 @@ {-# LANGUAGE TypeOperators #-}-+-- |+-- Module : Data.OI.System+-- Copyright : (c) Nobuo Yamashita 2011-2016+-- License : BSD3+-- Author : Nobuo Yamashita+-- Maintainer : nobsun@sampou.org+-- Stability : experimental+-- module Data.OI.System ( args