Y
HN Search
Hacker News Search
new
|
comments
|
top
|
jobs
detrino
searching PlanetScale…
1.
▲
2.
▲
3.
▲
4.
▲
5.
▲
6.
▲
23 ms
·
181.
▲
by
detrino
13y ago
I played with Rust for a day and while I was impressed with the language as a whole, I felt the borrow checker left a lot to be desired. I don't think having lifetime of references tied to scope works well in general. This is most evid
182.
▲
by
detrino
13y ago
Except for the poorly written examples that do quadratic string concatenation, this is just a benchmark of string searching, everything else is irrelevant.
183.
▲
by
detrino
13y ago
If you need memory efficiency you can just use a B-Tree, which also has the advantage of being more cache efficient.
184.
▲
by
detrino
13y ago
A quick C++ implementation: http://ideone.com/hGtbts While this was easy to do in ~10 minutes using gedit/clang/valgrind, I have to wonder how well I would have done had I been forced to use a whiteboard. > Eve
185.
▲
by
detrino
13y ago
The Graphics module is a core Ocaml library that is always available. In order to use it, it must be linked on the command line, similar to many other languages. Installing an unrelated OpenGL binding didn't magically make "ocaml
186.
▲
by
detrino
13y ago
Ocaml was always the more pragmatic language and for a long time the implementation was significantly faster than anything SML offered. MLton came along very late in the game and offers excellent performance, but doesn't support separa
187.
▲
by
detrino
13y ago
For reference, here is the tutorial's example reformatted in a more reasonable way: open Random open Graphics let rec iterate r x_init i = if i = 1 then x_init else let x = iterate r x_init (i
188.
▲
by
detrino
13y ago
;; is a special token used only in the REPL to force evaluation, it is not something you ever use in real code.
189.
▲
by
detrino
13y ago
I understand your point now, I thought you were mainly referring to the stack space quick sort uses. Edit: A comment above claims that without this bound, quicksort isn't even log n space.
190.
▲
by
detrino
13y ago
Heap sort is an example of an in-place sorting algorithm that is constant space. Just because this implementation uses some kind of fixed size buffer, doesn't mean it has an upper limit for the amount of data it can sort. It is possibl
191.
▲
by
detrino
13y ago
I never meant to imply that changing "<= n" to "!= n + 1" does not change the semantics of the unsigned loop. This was an example shown in some LLVM documentation as to why you should use signed loop variables. I was
192.
▲
by
detrino
13y ago
Right, but the same is true of signed as well.
193.
▲
by
detrino
13y ago
I took a couple examples where gcc failed vectorization for unsigned indexes and tried to rewrite them in a way that didn't sacrifice 1/2 of the type's range just to satisfy the optimizer. In the first example I could just ch
194.
▲
by
detrino
13y ago
I'm curious if there is a way to rewrite your loops which use unsigned types to somehow communicate to the compiler that you will not overflow.
195.
▲
by
detrino
13y ago
From clang's source code: // switch(bool_expr) {...} is often a programmer error, e.g. // switch(n && mask) { ... } // Doh - should be "n & mask". // One can a
196.
▲
by
detrino
13y ago
Why do you find it limiting ?
197.
▲
by
detrino
13y ago
That's not typically what people mean when they talk about RAII, you are still wrong. Every collection in the standard library is an RAII class.
198.
▲
by
detrino
13y ago
No, RAII is a general technique with an object owning a resource, to limit it to those 2 things is just wrong. When using std::shared_ptr, cycles are rarely a problem. Also, I don't think MLton ever implemented anything relating to reg
199.
▲
by
detrino
13y ago
Perhaps its more fair to C to consider handle to be an opaque type like C#/C++. In that case the acquire block can be rewritten: handle a, b, c; if (!aquire_handle(&a, 0)) goto fail1; if (!aquire_handle(&b, 1)) go
200.
▲
by
detrino
13y ago
Thanks for the example, seems like Go's solution is better than C but has the same problems as C#: non composable and leaky.
201.
▲
by
detrino
13y ago
Thanks for that, updated the example.
202.
▲
by
detrino
13y ago
It's worse than that, using longjmp to skip a non-trivial destructor is UB.
203.
▲
by
detrino
13y ago
To better understand the importance of RAII, you might consider what some other languages offer to solve similar problems. Consider a C example: int f() { int ret = -1; handle * a = acquire_handle(0); if (
204.
▲
by
detrino
13y ago
So what caused the bug ?
205.
▲
by
detrino
13y ago
C11/C++11 define a memory model and provide assorted primitives.
206.
▲
by
detrino
13y ago
Nice result :) Btw, it's tempting to use std::function in the same way as you would use a function in Haskell, but it usually isn't a very good idea. In C++ std::function is for when you want type erasure, usually because you wish
207.
▲
by
detrino
13y ago
This doesn't appear to have anything to do with type classes or overloading, but rather with (unconstrained) parametric polymorphism. Such a function is easy to write in C++, but the function prototype can not provide a strong guarante
208.
▲
by
detrino
13y ago
Can you give an example of what you mean?
209.
▲
by
detrino
13y ago
C++ doesn't need type classes as it has more powerful overloading. this is valid C++14: template<typename A, typename B> auto add(A a, B b) { return a + b; }
210.
▲
by
detrino
13y ago
That's not really true. A C++ compiler will verify that an instantiated template type checks. What concepts gives you is better error messages, overloading, and I presume it allows type checking of uninstantiated templates.
More ›