-
Notifications
You must be signed in to change notification settings - Fork 237
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ new ] IO buffering, and loops (#2367)
* [ new ] IO conditionals & loops * [ new ] stdin, stdout, stderr, buffering, etc. * [ fix ] and test for the new IO primitives * [ fix ] compilation * [ fix ] more import fixing * [ done (?) ] with compilation fixes * [ test ] add test to runner * [ doc ] explain the loop * [ compat ] add deprecated stub * [ fix ] my silly mistake * [ doc ] list re-exports in CHANGELOG
- Loading branch information
1 parent
1442ee7
commit c234c72
Showing
22 changed files
with
295 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
------------------------------------------------------------------------ | ||
-- The Agda standard library | ||
-- | ||
-- IO handles: simple bindings to Haskell types and functions | ||
------------------------------------------------------------------------ | ||
|
||
{-# OPTIONS --cubical-compatible --guardedness #-} | ||
|
||
module IO.Handle where | ||
|
||
open import Level using (Level) | ||
open import Data.Unit.Polymorphic.Base using (⊤) | ||
open import IO.Base using (IO; lift; lift′) | ||
|
||
private variable a : Level | ||
|
||
------------------------------------------------------------------------ | ||
-- Re-exporting types and constructors | ||
|
||
open import IO.Primitive.Handle as Prim public | ||
using ( BufferMode | ||
; noBuffering | ||
; lineBuffering | ||
; blockBuffering | ||
; Handle | ||
; stdin | ||
; stdout | ||
; stderr | ||
) | ||
|
||
------------------------------------------------------------------------ | ||
-- Wrapping functions | ||
|
||
hSetBuffering : Handle → BufferMode → IO {a} ⊤ | ||
hSetBuffering hdl bm = lift′ (Prim.hSetBuffering hdl bm) | ||
|
||
hGetBuffering : Handle → IO BufferMode | ||
hGetBuffering hdl = lift (Prim.hGetBuffering hdl) | ||
|
||
hFlush : Handle → IO {a} ⊤ | ||
hFlush hdl = lift′ (Prim.hFlush hdl) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,15 @@ | ||
------------------------------------------------------------------------ | ||
-- The Agda standard library | ||
-- | ||
-- Primitive IO: simple bindings to Haskell types and functions | ||
-- This module is DEPRECATED. Please use IO.Primitive.Core instead | ||
------------------------------------------------------------------------ | ||
|
||
-- NOTE: the contents of this module should be accessed via `IO`. | ||
|
||
{-# OPTIONS --cubical-compatible #-} | ||
|
||
module IO.Primitive where | ||
|
||
open import Level using (Level) | ||
private | ||
variable | ||
a : Level | ||
A B : Set a | ||
|
||
------------------------------------------------------------------------ | ||
-- The IO monad | ||
|
||
open import Agda.Builtin.IO public | ||
using (IO) | ||
|
||
infixl 1 _>>=_ | ||
|
||
postulate | ||
pure : A → IO A | ||
_>>=_ : IO A → (A → IO B) → IO B | ||
|
||
{-# COMPILE GHC pure = \_ _ -> return #-} | ||
{-# COMPILE GHC _>>=_ = \_ _ _ _ -> (>>=) #-} | ||
{-# COMPILE UHC pure = \_ _ x -> UHC.Agda.Builtins.primReturn x #-} | ||
{-# COMPILE UHC _>>=_ = \_ _ _ _ x y -> UHC.Agda.Builtins.primBind x y #-} | ||
open import IO.Primitive.Core public | ||
|
||
-- Haskell-style alternative syntax | ||
return : A → IO A | ||
return = pure | ||
{-# WARNING_ON_IMPORT | ||
"IO.Primitive was deprecated in v2.1. Use IO.Primitive.Core instead." | ||
#-} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
------------------------------------------------------------------------ | ||
-- The Agda standard library | ||
-- | ||
-- Primitive IO: simple bindings to Haskell types and functions | ||
------------------------------------------------------------------------ | ||
|
||
-- NOTE: the contents of this module should be accessed via `IO`. | ||
|
||
{-# OPTIONS --cubical-compatible #-} | ||
|
||
module IO.Primitive.Core where | ||
|
||
open import Level using (Level) | ||
private | ||
variable | ||
a : Level | ||
A B : Set a | ||
|
||
------------------------------------------------------------------------ | ||
-- The IO monad | ||
|
||
open import Agda.Builtin.IO public | ||
using (IO) | ||
|
||
infixl 1 _>>=_ | ||
|
||
postulate | ||
pure : A → IO A | ||
_>>=_ : IO A → (A → IO B) → IO B | ||
|
||
{-# COMPILE GHC pure = \_ _ -> return #-} | ||
{-# COMPILE GHC _>>=_ = \_ _ _ _ -> (>>=) #-} | ||
{-# COMPILE UHC pure = \_ _ x -> UHC.Agda.Builtins.primReturn x #-} | ||
{-# COMPILE UHC _>>=_ = \_ _ _ _ x y -> UHC.Agda.Builtins.primBind x y #-} | ||
|
||
-- Haskell-style alternative syntax | ||
return : A → IO A | ||
return = pure |
Oops, something went wrong.