Skip to content

Commit 3a1d216

Browse files
authored
[ fix #1368 ] ⊤-returning IO functions made level polymorphic (#1369)
1 parent e4a715f commit 3a1d216

File tree

3 files changed

+22
-13
lines changed

3 files changed

+22
-13
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ Bug-fixes
2727

2828
* Added version to library name
2929

30+
* In `IO`, ``-returning functions (such as `putStrLn`) have been made level polymorphic.
31+
This may force you to add more type or level annotations to your programs.
32+
3033
Non-backwards compatible changes
3134
--------------------------------
3235

README/Debug/Trace.agda

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,13 @@ div m n = just (go m m) where
5656
-- We add two calls to trace to see when div is evaluated and when the returned
5757
-- number is forced (by a call to show).
5858

59+
open import Level using (0ℓ)
5960
open import IO
6061

6162
main =
6263
let r = trace "Call to div" (div 4 2)
6364
j = λ n trace "Forcing the result wrapped in just." (putStrLn (show n)) in
64-
run (maybe′ j (return _) r)
65+
run {a = 0ℓ} (maybe′ j (return _) r)
6566

6667
-- We get the following trace where we can see that checking that the
6768
-- maybe-solution is just-headed does not force the natural number. Once forced,

src/IO.agda

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ open import Codata.Musical.Notation
1212
open import Codata.Musical.Costring
1313
open import Data.Unit.Polymorphic
1414
open import Data.String
15+
import Data.Unit as Unit0
1516
open import Function
1617
import IO.Primitive as Prim
1718
open import Level
@@ -145,28 +146,32 @@ readFile f = lift (Prim.readFile f)
145146
readFiniteFile : String IO String
146147
readFiniteFile f = lift (Prim.readFiniteFile f)
147148

148-
writeFile∞ : String Costring IO ⊤
149-
writeFile∞ f s = ignore (lift (Prim.writeFile f s))
149+
private
150+
lift′ : Prim.IO Unit0.⊤ IO {a} ⊤
151+
lift′ io = lift (io Prim.>>= λ _ Prim.return _)
152+
153+
writeFile∞ : String Costring IO {a} ⊤
154+
writeFile∞ f s = lift′ (Prim.writeFile f s)
150155

151-
writeFile : String String IO ⊤
156+
writeFile : String String IO {a}
152157
writeFile f s = writeFile∞ f (toCostring s)
153158

154-
appendFile∞ : String Costring IO ⊤
155-
appendFile∞ f s = ignore (lift (Prim.appendFile f s))
159+
appendFile∞ : String Costring IO {a}
160+
appendFile∞ f s = lift (Prim.appendFile f s)
156161

157-
appendFile : String String IO ⊤
162+
appendFile : String String IO {a}
158163
appendFile f s = appendFile∞ f (toCostring s)
159164

160-
putStr∞ : Costring IO ⊤
161-
putStr∞ s = ignore (lift (Prim.putStr s))
165+
putStr∞ : Costring IO {a}
166+
putStr∞ s = lift (Prim.putStr s)
162167

163-
putStr : String IO ⊤
168+
putStr : String IO {a}
164169
putStr s = putStr∞ (toCostring s)
165170

166-
putStrLn∞ : Costring IO ⊤
167-
putStrLn∞ s = ignore (lift (Prim.putStrLn s))
171+
putStrLn∞ : Costring IO {a}
172+
putStrLn∞ s = lift (Prim.putStrLn s)
168173

169-
putStrLn : String IO ⊤
174+
putStrLn : String IO {a}
170175
putStrLn s = putStrLn∞ (toCostring s)
171176

172177
-- Note that the commands writeFile, appendFile, putStr and putStrLn

0 commit comments

Comments
 (0)