Skip to content

Instantly share code, notes, and snippets.

View gsuuon's full-sized avatar

Steven Sun gsuuon

View GitHub Profile
@jdh30
jdh30 / JsonParser.fs
Last active January 30, 2024 14:06
Simple JSON parser written in F# using active patterns
type Json =
| Null
| Bool of bool
| Number of float
| String of string
| Array of Json list
| Object of (string * Json) list
type Bracket = Open | Close
open System
type Cont<'T> =
abstract Call<'R> : ('T -> 'R) * (exn -> 'R) -> 'R
let protect f x cont econt =
let res = try Choice1Of2 (f x) with err -> Choice2Of2 err
match res with
| Choice1Of2 v -> cont v
| Choice2Of2 v -> econt v