Commit 482aae22 authored by bbr's avatar bbr
Browse files

removed prim_bind and prim_return

parent 66cde0c0
module ExternalFunctionsDirectory where
import Curry
import CurryPrelude
import CurryPrelude hiding (return)
import CurryTime
import System.Time
......
module ExternalFunctionsIO where
import Curry
import CurryPrelude
import CurryPrelude hiding (return)
import InstancesIO
import qualified System.IO as SI
......
module ExternalFunctionsIOExts where
import Curry
import CurryPrelude
import CurryPrelude hiding (return)
import CurryIO
import ExternalDataIOExts
......
module ExternalFunctionsInteractive where
import Curry
import CurryPrelude
import CurryPrelude hiding (return)
printTerm :: (Show t0,Curry t0) => t0 -> Result (C_IO T0)
printTerm x _ = C_IO (\ _ -> print x >> return (IOVal T0))
......
module ExternalFunctionsMeta where
import Curry hiding ( trace )
import CurryPrelude hiding ( (==) )
import CurryPrelude hiding ( (==) , return , (>>=))
import CurryArray
import InstancesMeta
......
module ExternalFunctionsPrelude where
import Prelude hiding ((==))
import qualified Prelude ((==))
import Prelude hiding ((==),(>>=),return)
import qualified Prelude ((==),(>>=),return)
import Data.Char (ord,chr)
import Curry
import List
......@@ -25,10 +25,10 @@ curryIO :: Curry a => (Result (C_IO a)) -> IO a
curryIO x = let st = emptyStore in ioStart st (x (Just st))
curryIOVoid :: Curry a => (Result (C_IO a)) -> IO ()
curryIOVoid x = curryIO x >> return ()
curryIOVoid x = curryIO x >> Prelude.return ()
ioStart :: Curry a => Store -> C_IO a -> IO a
ioStart st (C_IO act) = act (Just st) >>= curryDo st
ioStart st (C_IO act) = act (Just st) Prelude.>>= curryDo st
ioStart _ (C_IOFail es) = printExceptions es
ioStart st (C_IOOr ref bs) = case fromStore st ref of
Nothing -> searchValC_IO (zipWith (mkChoice st ref) [0..] bs)
......@@ -40,23 +40,23 @@ ioStart st (C_IOSusp _ contRef) = do
Just v -> ioStart st v
curryDo :: Curry a => Store -> IOVal a -> IO a
curryDo _ (IOVal x) = return x
curryDo _ (IOVal x) = Prelude.return x
curryDo _ (IOValFail es) = printExceptions es
curryDo st (IOValOr ref bs) = case fromStore st ref of
Nothing -> searchIOVal (zipWith (mkChoice st ref) [0..] bs)
Just i -> (bs !! i) >>= curryDo st
Just i -> (bs !! i) Prelude.>>= curryDo st
curryDo st (IOValSusp _ contRef) = do
cont <- readIORef contRef
case cont () of
Nothing -> error "top io action is suspension"
Just v -> v >>= curryDo st
Just v -> v Prelude.>>= curryDo st
mkChoice :: Store -> OrRef -> Int -> a -> (Store,a)
mkChoice st ref i x = (addToStore st ref i,x)
searchValC_IO :: Curry a => [(Store,C_IO a)] -> IO a
searchValC_IO [] = error "no solution in branching io"
searchValC_IO ((st,C_IO act) : _) = act (Just st) >>= curryDo st
searchValC_IO ((st,C_IO act) : _) = act (Just st) Prelude.>>= curryDo st
searchValC_IO ((_ ,C_IOFail _) : xs) = searchValC_IO xs
searchValC_IO ((st,C_IOOr ref bs) : xs) =
-- switch arguments of (++) for breadth first (bad.), cf. also below
......@@ -72,7 +72,7 @@ searchIOVal [] = error "no solution in branching io value"
searchIOVal ((st,act) : stacts) = do
x <- act
case x of
IOVal a -> return a
IOVal a -> Prelude.return a
IOValFail _ -> searchIOVal stacts
-- switch arguments of (++) for breadth first (bad.)
IOValOr ref bs -> searchIOVal (zipWith (mkChoice st ref) [0..] bs ++ stacts)
......@@ -234,14 +234,14 @@ andBreadth :: List C_Bool -> Result C_Bool
andBreadth xs st = startBreadth (toHaskellList xs) st
-- TODO: C_IO without State??? also other io-functions.
prim_bind :: (Curry a,Curry b) => C_IO a -> Prim (a -> Result (C_IO b)) -> Result (C_IO b)
prim_bind m f _ = C_IO (hnfCTC (exec f) m)
(>>=) :: (Curry a,Curry b) => C_IO a -> Prim (a -> Result (C_IO b)) -> Result (C_IO b)
(>>=) m f _ = C_IO (hnfCTC (exec f) m)
exec :: (Curry a,Curry b) => Prim (a -> Result (C_IO b)) -> C_IO a -> Result (IO (IOVal b))
exec f (C_IO m) st = m st >>= \ x -> prim_do f x st
exec f (C_IO m) st = m st Prelude.>>= \ x -> prim_do f x st
-- if it wasn't io, we could just write
--exec f st (C_IO m) = m st >>= hnfCTC (fromIOVal f) st
--exec f st (C_IO m) = m st Prelude.>>= hnfCTC (fromIOVal f) st
-- with fromIOVal simply being
--fromIOVal::(Curry a,Curry b)=>Prim(a->C_IO b)->State->IOVal a->IO(IOVal b)
--fromIOVal f st (IOVal res) = hnfCTC exec2 st (apply f res)
......@@ -254,16 +254,16 @@ prim_do :: (Curry a,Curry b) =>
Prim (a -> Result (C_IO b)) -> IOVal a -> Result (IO (IOVal b))
prim_do f x state = case x of
IOVal res -> hnfCTC exec2 (apply f res state) state
IOValFail es -> return (IOValFail es)
IOValFail es -> Prelude.return (IOValFail es)
IOValOr ref bs ->
case state of
Nothing -> mapOr (\ x st -> x >>= \ x' -> prim_do f x' st) ref bs state
Nothing -> mapOr (\ x st -> x Prelude.>>= \ x' -> prim_do f x' st) ref bs state
Just store ->
case fromStore store ref of
Nothing ->
return (IOValOr ref
(zipWith (ctcBranch (\ x st -> x >>= \ x' -> cont x' st) ref store) [0..] bs))
Just i -> (bs!!i) >>= \ x' -> prim_do f x' state
Prelude.return (IOValOr ref
(zipWith (ctcBranch (\ x st -> x Prelude.>>= \ x' -> cont x' st) ref store) [0..] bs))
Just i -> (bs!!i) Prelude.>>= \ x' -> prim_do f x' state
IOValFreeVar ref -> case binding x of
--Left i -> IOValSusp True (findBindIO cont i)
Right v -> prim_do f v state --hnfCTC exec2 state (apply f v)
......@@ -278,8 +278,8 @@ exec2 :: C_IO b -> Result (IO (IOVal b))
exec2 (C_IO f) = f
prim_return :: Curry a => a -> Result (C_IO a)
prim_return a _ = C_IO (hnfCTC (\ x _ -> return (IOVal x)) a)
return :: Curry a => a -> Result (C_IO a)
return a _ = C_IO (hnfCTC (\ x _ -> Prelude.return (IOVal x)) a)
prim_putChar :: C_Char -> Result (C_IO T0)
prim_putChar = ioFunc1 putChar
......@@ -303,7 +303,7 @@ prim_show :: (Show a,Curry a) => a -> Result C_String
prim_show x _ = toCurry (show x)
getSearchTree :: Curry a => a -> Result (C_IO (C_SearchTree a))
getSearchTree x _ = C_IO (\ state -> return (IOVal (searchTr x state)))
getSearchTree x _ = C_IO (\ state -> Prelude.return (IOVal (searchTr x state)))
searchTr :: Curry a => a -> Result (C_SearchTree a)
......@@ -402,23 +402,23 @@ hnf2 :: (Curry a, Curry b,Curry c) => (a->b->c) -> a -> b -> Result c
hnf2 f x y = hnfCTC (\ x' -> hnfCTC (\ y' _ -> f x' y') y) x
ioFunc0 :: (Curry b,ConvertCH b a) => IO a -> Result (C_IO b)
ioFunc0 iof _ = C_IO (\ _ -> iof >>= \hv -> return (IOVal (toCurry hv)))
ioFunc0 iof _ = C_IO (\ _ -> iof Prelude.>>= \hv -> Prelude.return (IOVal (toCurry hv)))
ioFunc1 :: (Curry a,Curry d,ConvertCH a b,ConvertCH d c) => (b->IO c) -> a -> Result (C_IO d)
ioFunc1 iof x _ = C_IO (\ _ ->
iof (fromCurry x) >>= \hv ->
return (IOVal (toCurry hv)))
iof (fromCurry x) Prelude.>>= \hv ->
Prelude.return (IOVal (toCurry hv)))
ioFunc2 :: (Curry a, Curry c,Curry f,ConvertCH a b,ConvertCH c d,ConvertCH f e) =>
(b->d->IO e) -> a -> c -> Result (C_IO f)
ioFunc2 iof x y _ = C_IO (\ _ ->
iof (fromCurry x) (fromCurry y) >>= \hv ->
return (IOVal (toCurry hv)))
iof (fromCurry x) (fromCurry y) Prelude.>>= \hv ->
Prelude.return (IOVal (toCurry hv)))
ioFunc3 iof x y z _ = C_IO (\ _ ->
iof (fromCurry x) (fromCurry y) (fromCurry z) >>= \hv ->
return (IOVal (toCurry hv)))
iof (fromCurry x) (fromCurry y) (fromCurry z) Prelude.>>= \hv ->
Prelude.return (IOVal (toCurry hv)))
ghnfCTC2 :: (Curry a, Curry b,Curry c) => (a->b->c) -> a -> b -> Result c
ghnfCTC2 f x y = ghnfCTC (\x'-> ghnfCTC (\ y' _ -> f x' y') y) x
......
module ExternalFunctionsSocket (module ExternalFunctionsSocket) where
import Curry
import CurryPrelude
import CurryPrelude hiding (return, (>>=))
import ExternalDataSocket
import CurryIO
......
module ExternalFunctionsSystem where
import Curry
import CurryPrelude
import CurryPrelude hiding (return,(>>=))
import qualified System.Environment as SE
import qualified System.CPUTime as SC
......
......@@ -738,24 +738,18 @@ data IO _ -- conceptually: World -> (a,World)
--- @return An action that first performs a (yielding result r)
--- and then performs (fa r)
(>>=) :: IO a -> (a -> IO b) -> IO b
(>>=) x y = prim_bind x y
prim_bind :: IO a -> (a -> IO b) -> IO b
prim_bind external
(>>=) external
--- The empty action that directly returns its argument.
return :: a -> IO a
return x = prim_return x
prim_return :: a -> IO a
prim_return external
return external
--- Sequential composition of actions.
--- @param a1 - An action
--- @param a2 - An action
--- @return An action that first performs a1 and then a2
(>>) :: IO _ -> IO b -> IO b
a >> b = a >>= (\_ -> b)
a >> b = a >>= const b
--- The empty action that returns nothing.
done :: IO ()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment