You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
defgetBytes (input : Array Nat) : StateT (Array UInt8) (Except String) Unit := do
215
+
defgetBytes (input : Array Nat) :
216
+
StateT (Array UInt8) (Except String) Unit := do
216
217
input.forM fun i =>
217
218
liftM (Except.tryCatch (some <$> getByte i) fun _ => pure none) >>=
218
219
fun
@@ -233,7 +234,10 @@ Ideally, state updates would be performed within the {name}`tryCatch` call direc
233
234
234
235
Attempting to save bytes and handled exceptions does not work, however, because the arguments to {name}`Except.tryCatch`have type {lean}`Except String Unit`:
defgetBytes' (input : Array Nat) : StateT (Array String) (StateT (Array UInt8) (Except String)) Unit := do
237
+
defgetBytes' (input : Array Nat) :
238
+
StateT (Array String)
239
+
(StateT (Array UInt8)
240
+
(Except String)) Unit := do
237
241
input.forM fun i =>
238
242
liftM
239
243
(Except.tryCatch
@@ -254,7 +258,10 @@ It provides the inner action with an interpreter for the outer monad.
254
258
In the case of {name}`StateT`, this interpreter expects that the inner monad returns a tuple that includes the updated state, and takes care of providing the initial state and extracting the updated state from the tuple.
255
259
256
260
```lean
257
-
defgetBytes' (input : Array Nat) : StateT (Array String) (StateT (Array UInt8) (Except String)) Unit := do
Copy file name to clipboardExpand all lines: Manual/Monads/Syntax.lean
+3-1Lines changed: 3 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -563,7 +563,9 @@ When iterating over multiple collections, iteration stops when any of the collec
563
563
564
564
When iterating over the valid indices for an array with {keywordOf Lean.Parser.Term.doFor}`for`, naming the membership proof allows the tactic that searches for proofs that array indices are in bounds to succeed.
0 commit comments