Skip to content

Commit

Permalink
Monad instances
Browse files Browse the repository at this point in the history
  • Loading branch information
liyishuai committed Sep 20, 2024
1 parent 420903f commit 7aac084
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions Decode.v
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,18 @@ Definition dpath' {T} (d : JDecode T) (s : string) (j : json) : string + T :=
(decode__jpath (this@s) j <|> inr JSON__Null) >>= d.

Definition dpath {T} `{JDecode T} : string -> JDecode T := dpath' decode.

#[global]
Instance Monad__JDecode: Monad JDecode :=
{ ret _ := const ∘ inr;
bind _ _ f k j := f j >>= flip k j
}.

#[global]
Instance MonadExc__JDecode: MonadExc string JDecode :=
{ raise _ := const ∘ inl;
catch _ m f j := match m j with
| inl e => f e j
| inr _ as mj => mj
end
}.

0 comments on commit 7aac084

Please sign in to comment.