The array read and write operations are now called: - "Comfortable" version (with runtime bound checks): `Array.get` and `Array.set` like OCaml. It is also consistent with `Ref.get` and `Ref.put`, and `get` and `set` for `MonadState`. - `Fin` version (without runtime bound checks): `Array.index` and `Array.update` like in F*. - `USize` version (without runtime bound checks and unboxing): `Array.idx` and `Array.updt`. cc @kha
17 lines
620 B
Text
17 lines
620 B
Text
def foo {m} [Monad m] [MonadExcept String m] [MonadState (Array Nat) m] : m Nat :=
|
|
catch (do modify $ λ a : Array Nat, a.set 0 33,
|
|
throw "error")
|
|
(λ _, do a ← get, pure $ a.get 0)
|
|
|
|
def ex₁ : StateT (Array Nat) (ExceptT String id) Nat :=
|
|
foo
|
|
|
|
def ex₂ : ExceptT String (StateT (Array Nat) id) Nat :=
|
|
foo
|
|
|
|
#exit
|
|
|
|
-- The following examples were producing an element of Type `id (Except String Nat)`.
|
|
-- Type class resolution was failing to produce an instance for `HasRepr (id (Except String Nat))` because `id` is not transparent.
|
|
#eval run ex₁ (mkArray 10 1000)
|
|
#eval run ex₂ (mkArray 10 1000)
|