- 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
|
#
¿
Jun 27, 2015 02:05
|
|
- Adbot
-
ADBOT LOVES YOU
|
|
#
¿
May 1, 2024 18:40
|
|