39 karma · joined Feb 15, 2015 (11y ago) · 20 submissions
comment 6y ago · link · parent
comment 6y ago · link · parent
comment 6y ago · link · parent
> However, when working directly with the hardware, which has no knowledge of Rust’s guarantees, it is necessary to work in Rust’s unsafe mode, which allows some additional behaviors, but requires the developer to uphold certain correctness guarantees manually.
If the whole code will be wrapped in unsafe blocks, then what is the point of using Rust?
comment 7y ago · link · parent
comment 7y ago · link · parent
> This function returns the first element from a list. Is it possible to implement?
But the type itself doesn't say that it must return the first element.
> If you see why parseNonEmpty is preferable, you understand what I mean by the mantra “parse, don’t validate.”
Okay, what about more complex cases? E.g. how do you describe type "such value doesn't exist in the db table yet"?
comment 7y ago · link · parent
const a = [...Array(1000000).keys()];
const m = 8;
let leftAvg = .0;
for(let _ of Array(m)) {
const t0 = performance.now();
a.map(Math.tan).map(Math.sin);
const t1 = performance.now();
leftAvg += (t1 - t0)/m;
}
let rightAvg = .0;
for(let _ of Array(m)) {
const t0 = performance.now();
a.map(x => Math.sin(Math.tan(x)));
const t1 = performance.now();
rightAvg += (t1 - t0)/m;
}
console.log(leftAvg, rightAvg, leftAvg/rightAvg);
// JS Firefox 70: 264 360.75 0.7318087318087318
var a = Enumerable.Range(0, 10000000).Select(x => (double)x).ToArray();
double[] xs1 = null;
double[] xs2 = null;
var m = 16;
var leftAvg = .0;
foreach (var _ in Enumerable.Range(0, m))
{
var watch = System.Diagnostics.Stopwatch.StartNew();
xs1 = a.Select(Math.Tan).ToArray().Select(Math.Sin).ToArray();
watch.Stop();
leftAvg += (double)watch.ElapsedMilliseconds / m;
}
var rightAvg = .0;
foreach (var _ in Enumerable.Range(0, m))
{
var watch = System.Diagnostics.Stopwatch.StartNew();
xs2 = a.Select(x => Math.Sin(Math.Tan(x))).ToArray();
watch.Stop();
rightAvg += (double)watch.ElapsedMilliseconds / m;
}
Console.WriteLine($"{leftAvg} {rightAvg} {leftAvg / rightAvg}");
// C# Results: 505.75 602.25 0.839767538397675comment 7y ago · link · parent
It doesn't look awful in Firefox, it looks perfect (it's version 26 of Firefox though.) This is what I see https://i.imgur.com/sjvqycv.png
comment 7y ago · link · parent
This can be solved in many ways [1][2] and I don't think haskell's approach is the one that can be imported.
[1]: https://www.microsoft.com/en-us/research/wp-content/uploads/...
comment 7y ago · link · parent
https://www.ghacks.net/wp-content/uploads/2013/07/firefox-do...
comment 7y ago · link · parent
comment 7y ago · link · parent
> Mr. Nesterchuk, the Belarus historian, said: “The Poles say he belongs to them. The Lithuanians, the Ukrainians say the same thing. The Americans, too.”
> “But I always say that Kosciuszko does not belong to anyone,” Mr. Nesterchuk added. “He belongs to the whole world as a true democrat and a fighter for freedom.”