Created
June 30, 2016 00:48
-
-
Save liammclennan/278178cf6e4ece528451518eb04474d0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#r @"packages\FParsec.1.0.1\lib\net40-client\FParsecCS.dll" | |
#r @"packages\FParsec.1.0.1\lib\net40-client\FParsec.dll" | |
open FParsec | |
let parsesA = pchar 'a' | |
run parsesA "abcdefg" | |
run (many anyChar) "abcde fg" | |
run (anyChar) "abcdefg" | |
|> sprintf "%+A" | |
run (pchar 'a') "abcdefg" | |
|> sprintf "%+A" | |
run (stringReturn "foo" 7) "foobar" | |
// (1.1) | |
let pfloatinparens = pchar '(' >>. pfloat .>> pchar ')' | |
run pfloatinparens "(1.1)" | |
let pfloatinparens' = between (pchar '(') (pchar ')') pfloat | |
run pfloatinparens' "(1.1)" | |
// parse 1.1, 3.7 | |
let plistoffloats = | |
(sepBy pfloat (pchar ',' .>> spaces)) | |
run plistoffloats "1.1, 3.7" | |
// (1.1, 3.7) | |
type Point = {x: float; y: float} | |
let ppoint = between (pchar '(') (pchar ')') plistoffloats |>> (fun (x::y::xs) -> {x = x; y = y}) | |
run ppoint "(1.1, 3.7)" | |
let plistoffloats' = | |
pipe3 pfloat (pchar ',' .>> spaces) pfloat (fun x z y -> {x = x; y = y}) | |
run plistoffloats' "1.1, 3.7" | |
let ppoint' = | |
between | |
(pchar '(') | |
(pchar ')') | |
plistoffloats' | |
run ppoint' "(1.1, 3.7)" | |
let fermats = seq { for x in 1..4 do yield pown 2 (pown 2 x) } | |
Seq.take 4 fermats |> Seq.toList |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment