oriented and imperative programming) Created by at Microsoft Research Production quality compiler, tools, libraries, and support Full blown project and ecosystem The core of the language was inspired by and code runs in the .NET framework Extended to be a first class language in the Don Syme Open Source OCaml CLI
x let toThePower xs power = Seq.map power xs let xs = toThePower [1; 2; 3; 4] let squares = (fun x -> x * x) |> xs let cubes = (fun x -> x * x * x) |> xs
computations Does not block a thread when I/O happens Sleeps happen Or other async operation is scheduled Based on the Async<'T> type at its core Which represents a value of type 'T at some point in the future Preserves the readability of synchronous code (avoid nested callbacks
printf "[Thread %d]" System.Threading.Thread.CurrentThread.ManagedThreadId; printfn fmt let urlList = [ "Wikipedia", "http://www.wikipedia.org" "The Times", "http://www.nytimes.com" "Le Monde", "http://www.lemonde.fr" ] let fetchAsync(name, url:string) = async { try let uri = new System.Uri(url) let webClient = new WebClient() let! html = webClient.AsyncDownloadString(uri) tprintfn "Read %d characters for %s" html.Length name with | ex -> tprintfn "%s" (ex.Message); } urlList |> Seq.map fetchAsync |> Async.Parallel |> Async.RunSynchronously |> ignore
query expressions, which I didn't show you) have a common "shape" They are generally known as Computation Expressions You can define your own! Create a builder type Implement the special methods that define how the fragments of the computation are combined: Bind Return Zero etc