Skip to content

Instantly share code, notes, and snippets.

@Maxdamantus

Maxdamantus/.ml Secret

Created July 29, 2018 03:21
Show Gist options
  • Save Maxdamantus/121c4931aba573541130f39997dea8aa to your computer and use it in GitHub Desktop.
Save Maxdamantus/121c4931aba573541130f39997dea8aa to your computer and use it in GitHub Desktop.
type ('s, 't) parser = 's -> ('t, 't) outcome
and ('s, 't) outcome = Fail | Success of { result: 't; state: 's; }
let fail s = Fail
let mapOutcome (f : 'a -> 'b) (o : ('s, 'a) outcome) : ('s, 'b) outcome = match o with
| Fail -> Fail
| Success { result = r; state; } -> Success { result = f r; state; }
let map
(f: 'x -> 'b)
(p: ('s, 'x) parser)
: (('s, 'b) parser) =
fun state0 -> mapOutcome f (p state0) (* with
| Fail -> Fail
| Success { result = (r : 'x); state; } -> Success { result = (f r : 'b); state; }
*)
type ('s, 't) parser = 's -> ('t, 't) outcome
and ('s, 't) outcome = Fail | Success of { result: 't; state: 's; }
val fail : ('s, 't) parser
val mapOutcome : ('a -> 'b) -> ('s, 'a) outcome -> ('s, 'b) outcome
val map : ('a -> 'b) -> ('s, 'a) parser -> ('s, 'b) parser
Error: The implementation parse.ml does not match the interface parse.cmi:
Values do not match:
val map : ('b -> 'b) -> ('s, 'b) parser -> ('s, 'b) parser
is not included in
val map : ('a -> 'b) -> ('s, 'a) parser -> ('s, 'b) parser
File "parse.ml", line 10, characters 4-7: Actual declaration
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment