Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Locked thread
TopherCStone
Feb 27, 2013

I am very important and deserve your attention
F# is really cool. I'm working through F# For Fun and Profit right now and it seems pretty good. There are times when it references something I don't understand and it's not always clear whether they assume I already have the knowledge or if it's going to be discussed in more detail later, but overall I like it.

edit: like this example is really cool

code:
// set up the vocabulary
type DateScale = Hour | Hours | Day | Days | Week | Weeks
type DateDirection = Ago | Hence

// define a function that matches on the vocabulary
let getDate interval scale direction =
    let absHours = match scale with
                    | Hour | Hours -> 1 * interval
                    | Day | Days -> 24 * interval
                    | Week | Weeks -> 24 * 7 * interval
    let signedHours = match direction with 
                       | Ago -> -1 * absHours
                       | Hence -> absHours
    System.DateTime.Now.AddHours(float signedHours)

// test some examples
let example1 = getDate 5 Days Ago
let example2 = getDate 1 Hour Hence
That would be annoyingly verbose in C#

Here's the output:
code:
val example1 : System.DateTime = 6/22/2015 4:30:52 PM
val example2 : System.DateTime = 6/27/2015 5:30:52 PM

TopherCStone fucked around with this message at 21:34 on Jun 27, 2015

Adbot
ADBOT LOVES YOU

  • Locked thread