Without do-notation | With do-notation | |
---|---|---|
Lazy | - | Haskell |
Strict | C++ | Where the Magic Happens |
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
open System | |
open System.Globalization | |
let parseIsoDateTime (s : string) = | |
let dt = DateTime.Parse(s, CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind) | |
assert (dt.Kind = DateTimeKind.Utc) | |
dt | |
let dt = parseIsoDateTime "2023-05-18T15:43:14.673Z" |
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
type Circle<'t when 't : (static member Zero : 't) | |
and 't : (static member One : 't) | |
and 't : (static member (+) : 't * 't -> 't) | |
and 't : (static member (-) : 't * 't -> 't) | |
and 't : (static member (*) : 't * 't -> 't) | |
and 't : (static member (/) : 't * 't -> 't) | |
and 't : (static member (~-) : 't -> 't) | |
and 't : (static member op_Explicit : float -> 't) > = | |
{ | |
Radius : 't |
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
[<Struct>] | |
type Stateful<'state, 'result> = | |
Stateful of ('state -> 'state * 'result) | |
type Delayed<'state, 'result> = unit -> Stateful<'state, 'result> | |
module State = | |
let update f = | |
Stateful (fun state -> f state, ()) |
🚨 This tutorial was written with Linux in mind. Windows and macOS users, please refer to Facebook's setup instructions.
You will need GCC / Clang, a text editor and Buck.
You probably have the first two, so here's how to install Buck for Linux:
- Open your User settings
- Add an language mapping from
"BUCK"
to"python"
like so:
{
"files.associations": {
"BUCK": "python"
}
}
I hereby claim:
- I am njlr on github.
- I am njlr (https://keybase.io/njlr) on keybase.
- I have a public key whose fingerprint is 8834 ACBB 3C42 089C 172B 5A1D C218 387C AD0C 52FE
To claim this, I am signing this object:
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
// There is an optimization opportunity when using a currying-style in JavaScript. | |
// For example, this... | |
export const and = x => y => x && !!y; | |
// Might become... | |
export const and = x => { | |
if (x) { | |
return y => !!y; | |
} |
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
// try-catch style | |
// | |
// Advantages: | |
// 1. Familiar to OOP developers | |
// 2. Explicit error-handling code not required | |
// 3. Works well with async-await syntax | |
// | |
// Disadvantages: | |
// 1. Inefficient | |
// 2. Explicit error-handling code not required |
NewerOlder