~ubuntu-branches/ubuntu/wily/agda/wily-proposed

« back to all changes in this revision

Viewing changes to examples/simple-lib/Lib/IO.agda

  • Committer: Package Import Robot
  • Author(s): Iain Lane
  • Date: 2014-08-05 06:38:12 UTC
  • mfrom: (1.1.6)
  • Revision ID: package-import@ubuntu.com-20140805063812-io8e77niomivhd49
Tags: 2.4.0.2-1
* [6e140ac] Imported Upstream version 2.4.0.2
* [2049fc8] Update Build-Depends to match control
* [93dc4d4] Install the new primitives
* [e48f40f] Fix typo dev→doc

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
 
2
 
module Lib.IO where
3
 
 
4
 
open import Lib.List
5
 
open import Lib.Prelude
6
 
 
7
 
{-# IMPORT System.Environment #-}
8
 
 
9
 
FilePath = String
10
 
 
11
 
postulate
12
 
  IO        : Set -> Set
13
 
  getLine   : IO String
14
 
  putStrLn  : String -> IO Unit
15
 
  putStr    : String -> IO Unit
16
 
  bindIO    : {A B : Set} -> IO A -> (A -> IO B) -> IO B
17
 
  returnIO  : {A : Set} -> A -> IO A
18
 
  getArgs   : IO (List String)
19
 
  readFile  : FilePath -> IO String
20
 
  writeFile : FilePath -> String -> IO Unit
21
 
 
22
 
{-# BUILTIN IO IO #-}
23
 
{-# COMPILED_TYPE IO IO #-}
24
 
 
25
 
{-# COMPILED putStr putStr #-}
26
 
{-# COMPILED putStrLn putStrLn #-}
27
 
{-# COMPILED bindIO (\_ _ -> (>>=) :: IO a -> (a -> IO b) -> IO b) #-}
28
 
{-# COMPILED returnIO (\_ -> return :: a -> IO a) #-}
29
 
  -- we need to throw away the type argument to return and bind
30
 
  -- and resolve the overloading explicitly (since Alonzo
31
 
  -- output is sprinkled with unsafeCoerce#).
32
 
{-# COMPILED getLine getLine #-}
33
 
{-# COMPILED getArgs System.Environment.getArgs #-}
34
 
{-# COMPILED readFile readFile #-}
35
 
{-# COMPILED writeFile writeFile #-}
36
 
 
37
 
mapM : {A B : Set} -> (A -> IO B) -> List A -> IO (List B)
38
 
mapM f [] = returnIO []
39
 
mapM f (x :: xs) = bindIO (f x) \y -> bindIO (mapM f xs) \ys -> returnIO (y :: ys)
40
 
 
41
 
mapM₋ : {A : Set} -> (A -> IO Unit) -> List A -> IO Unit
42
 
mapM₋ f xs = bindIO (mapM f xs) \_ -> returnIO unit