Skip to content

Instantly share code, notes, and snippets.

@mrange
Last active July 12, 2018 07:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrange/ac3f3d2c3bbb5efb1711e717d6112ac1 to your computer and use it in GitHub Desktop.
Save mrange/ac3f3d2c3bbb5efb1711e717d6112ac1 to your computer and use it in GitHub Desktop.
let cuteParse =
let split (c: char) (s: string) = s.Split c
let trim (s: string) = s.Trim ()
let op c r f = split c >> Seq.map (trim >> f) >> Seq.reduce r
int |> op '/' (/) |> op '*' (*) |> op '-' (-) |> op '+' (+)
[<EntryPoint>]
let main argv =
let examples = [| "1"; "1-3"; "1*3"; "1 + 2*3 - 2" |]
for example in examples do
printfn "%s -> %d" example <| cuteParse example
0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment