| 1 |
------------------------------------------------------------------------ |
| 2 |
-- The Agda standard library |
| 3 |
-- |
| 4 |
-- Primitive IO: simple bindings to Haskell types and functions |
| 5 |
-- manipulating potentially infinite objects |
| 6 |
------------------------------------------------------------------------ |
| 7 |
|
| 8 |
{-# OPTIONS --cubical-compatible --guardedness #-} |
| 9 |
|
| 10 |
module IO.Primitive.Infinite where |
| 11 |
|
| 12 |
-- NOTE: the contents of this module should be accessed via `IO` or |
| 13 |
-- `IO.Infinite`. |
| 14 |
|
| 15 |
open import Codata.Musical.Costring using (Costring) |
| 16 |
open import Agda.Builtin.String using (String) |
| 17 |
open import Agda.Builtin.Unit renaming (⊤ to Unit) |
| 18 |
|
| 19 |
------------------------------------------------------------------------ |
| 20 |
-- The IO monad |
| 21 |
|
| 22 |
open import Agda.Builtin.IO public using (IO) |
| 23 |
|
| 24 |
------------------------------------------------------------------------ |
| 25 |
-- Simple lazy IO |
| 26 |
|
| 27 |
-- Note that the functions below produce commands which, when |
| 28 |
-- executed, may raise exceptions. |
| 29 |
|
| 30 |
-- Note also that the semantics of these functions depends on the |
| 31 |
-- version of the Haskell base library. If the version is 4.2.0.0 (or |
| 32 |
-- later?), then the functions use the character encoding specified by |
| 33 |
-- the locale. For older versions of the library (going back to at |
| 34 |
-- least version 3) the functions use ISO-8859-1. |
| 35 |
|
| 36 |
|
| 37 |
postulate |
| 38 |
getContents : IO Costring |
| 39 |
readFile : String → IO Costring |
| 40 |
writeFile : String → Costring → IO Unit |
| 41 |
appendFile : String → Costring → IO Unit |
| 42 |
putStr : Costring → IO Unit |
| 43 |
putStrLn : Costring → IO Unit |
| 44 |
|
| 45 |
{-# FOREIGN GHC import qualified Data.Text #-} |
| 46 |
|
| 47 |
{-# FOREIGN GHC |
| 48 |
|
| 49 |
fromColist :: MAlonzo.Code.Codata.Musical.Colist.Base.AgdaColist a -> [a] |
| 50 |
fromColist MAlonzo.Code.Codata.Musical.Colist.Base.Nil = [] |
| 51 |
fromColist (MAlonzo.Code.Codata.Musical.Colist.Base.Cons x xs) = |
| 52 |
x : fromColist (MAlonzo.RTE.flat xs) |
| 53 |
|
| 54 |
toColist :: [a] -> MAlonzo.Code.Codata.Musical.Colist.Base.AgdaColist a |
| 55 |
toColist [] = MAlonzo.Code.Codata.Musical.Colist.Base.Nil |
| 56 |
toColist (x : xs) = |
| 57 |
MAlonzo.Code.Codata.Musical.Colist.Base.Cons x (MAlonzo.RTE.Sharp (toColist xs)) |
| 58 |
#-} |
| 59 |
|
| 60 |
{-# COMPILE GHC getContents = fmap toColist getContents #-} |
| 61 |
{-# COMPILE GHC readFile = fmap toColist . readFile . Data.Text.unpack #-} |
| 62 |
{-# COMPILE GHC writeFile = \x -> writeFile (Data.Text.unpack x) . fromColist #-} |
| 63 |
{-# COMPILE GHC appendFile = \x -> appendFile (Data.Text.unpack x) . fromColist #-} |
| 64 |
{-# COMPILE GHC putStr = putStr . fromColist #-} |
| 65 |
{-# COMPILE GHC putStrLn = putStrLn . fromColist #-} |
| 66 |
{-# COMPILE UHC getContents = UHC.Agda.Builtins.primGetContents #-} |
| 67 |
{-# COMPILE UHC readFile = UHC.Agda.Builtins.primReadFile #-} |
| 68 |
{-# COMPILE UHC writeFile = UHC.Agda.Builtins.primWriteFile #-} |
| 69 |
{-# COMPILE UHC appendFile = UHC.Agda.Builtins.primAppendFile #-} |
| 70 |
{-# COMPILE UHC putStr = UHC.Agda.Builtins.primPutStr #-} |
| 71 |
{-# COMPILE UHC putStrLn = UHC.Agda.Builtins.primPutStrLn #-} |