{-# OPTIONS --cubical-compatible --guardedness #-}
module IO where
open import Codata.Musical.Notation
open import Codata.Musical.Costring
open import Data.Unit.Polymorphic.Base
open import Data.String.Base using (String)
import Data.Unit.Base as Unit0
open import Function.Base using (_∘_; flip)
import IO.Primitive.Core as Prim
open import Level
private
variable
a b : Level
A : Set a
B : Set b
open import IO.Base public
open import IO.Handle public
module Colist where
open import Codata.Musical.Colist.Base
sequence : Colist (IO A) → IO (Colist A)
sequence [] = pure []
sequence (c ∷ cs) = bind (♯ c) λ x → ♯
bind (♯ sequence (♭ cs)) λ xs → ♯
pure (x ∷ ♯ xs)
sequence′ : Colist (IO A) → IO ⊤
sequence′ [] = pure _
sequence′ (c ∷ cs) = seq (♯ c) (♯ sequence′ (♭ cs))
mapM : (A → IO B) → Colist A → IO (Colist B)
mapM f = sequence ∘ map f
mapM′ : (A → IO B) → Colist A → IO ⊤
mapM′ f = sequence′ ∘ map f
forM : Colist A → (A → IO B) → IO (Colist B)
forM = flip mapM
forM′ : Colist A → (A → IO B) → IO ⊤
forM′ = flip mapM′
module List where
open import Data.List.Base
sequence : List (IO A) → IO (List A)
sequence [] = ⦇ [] ⦈
sequence (c ∷ cs) = ⦇ c ∷ sequence cs ⦈
sequence′ : List (IO A) → IO ⊤
sequence′ [] = pure _
sequence′ (c ∷ cs) = c >> sequence′ cs
mapM : (A → IO B) → List A → IO (List B)
mapM f = sequence ∘ map f
mapM′ : (A → IO B) → List A → IO ⊤
mapM′ f = sequence′ ∘ map f
forM : List A → (A → IO B) → IO (List B)
forM = flip mapM
forM′ : List A → (A → IO B) → IO ⊤
forM′ = flip mapM′
open import IO.Finite public
renaming (readFile to readFiniteFile)
open import IO.Infinite public
renaming ( writeFile to writeFile∞
; appendFile to appendFile∞
; putStr to putStr∞
; putStrLn to putStrLn∞
)