Close

An F# HelloWorld Style Crawler / Scraper (if you may)

I wrote/scavenge this while Amanda Laucher's F# talk yesterday. It's a beauty, this terse F# syntactically & semantically. Having worked with scheme, experimenting with F# comes naturally however James Iry during a 1-1 discussions begs to differ that they are QUITE different. I have yet to independently verify the merit of this claim.

open System.IO
open System.Net            
            
let GetUrl(url:string) =

    let req = WebRequest.Create(url)

    // Get the response, synchronously
    let rsp = req.GetResponse()

    // Grab the response stream and a reader. Clean up when we're done
    use stream = rsp.GetResponseStream()
    use reader = new StreamReader(stream)

    // Synchronous read-to-end, returning the result
    reader.ReadToEnd()

let result = GetUrl("http://www.google.com")
printfn "%s" result

Share

1 thought on “An F# HelloWorld Style Crawler / Scraper (if you may)

  1. F# comes out of the ML family of languages. That family shares with Scheme the fact that functions are values and that free variables in lambdas are lexically scoped. So they're certainly closer to each other than they are to C or Fortran or Java.

    But

    Scheme: dynamically typed
    ML: statically typed - the type system is in fact one of the main reasons ML was invented

    Scheme: all variables are mutable
    ML: variables are immutable unless marked otherwise

    Scheme: macros are part of the language definition and important to how you write it
    ML: macros exist in some extensions of some variation on ML

    Scheme: call-with-current-continuation
    ML: nope

Comments are closed.