Skip to content

Instantly share code, notes, and snippets.

@CoditCompany
Last active October 5, 2017 07:22
Show Gist options
  • Select an option

  • Save CoditCompany/c4029ee5c41fd854d9adbebd1eb43c98 to your computer and use it in GitHub Desktop.

Select an option

Save CoditCompany/c4029ee5c41fd854d9adbebd1eb43c98 to your computer and use it in GitHub Desktop.
// Parser<('a -> 'b), 'u> -> Parser<'a, 'u> -> Parser<'b, 'u>
let apply fp xp =
pipe2 fp xp (fun f x -> f x)
// ('a -> Parser<'b, 'u>) -> 'a list -> Parser<'b list, 'u>
let traverse f list =
let (<*>) = apply
let retn = preturn
let cons head tail = head :: tail
let init = retn []
let folder head tail =
retn cons <*> (f head) <*> tail
List.foldBack folder list init
// Parser<'a, 'u> list -> Parser<'a list, 'u>
let sequence x = traverse id x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment