HNHacker News
TopNewBestAskShowJobs

andolanra

1,874 karma · joined July 19, 2010

submissionscomments
andolanra··on Coconut – Pythonic functional programming language
It looks like data declarations get translated to immutable subclasses of collections.namedtuple in such a way that you can match on the resulting values. So it's really less like an algebraic data type and more like one of Scala's case classes.
andolanra··on A list of command line tools for manipulating structured text data
jq is powerful enough to express it in one query: it has variables (using expr as name) which make this thing at least vaguely feasible. That doesn't mean you should, but you could:

    .models
      | (.[]
        | if .title == "farmers"
          then
              (.fields | .[] | if .name == "Fruits" then .key else empty end)
                as $fruits
            | (.fields | .[] | if .name == "Full name" then .key else empty end)
                as $name
            | .entities
            | .[]
            | if .[ $name ] == "Bob, the farmer" then .[ $fruits ] else empty end
          else empty end)
            as $fruits
      | .[]
      | if .["title"] == "fruits"
          then
             ( .fields | .[] | if .name == "Name" then .key else empty end) as $fruit_name
             | .entities | [ .[] | {(._id): .[$fruit_name]} ] | add as $lookup
             | $fruits | .[] | $lookup[.]
          else empty
        end
(I'm not claiming this is the best way to write that query, but it's the first one I came up with.)
andolanra··on Unix’s file durability problem
I'm not actually sure whether this actually helps with the problem described in the post, but such a thing does exist:

https://github.com/guardianproject/libsqlfs

andolanra··on No Compiler – On LLVM, and writing software without a compiler
Terra is lower-level, and on evaluation compiles to object code. Lua is higher-level, and on evaluation compiles to bytecode before being executed. A source file written entirely in Terra would produce a binary, and a source file written in Lua would produce Lua bytecode. In either case, you can run the result immediately, or save the resulting object code/bytecode to run later.

The strength of the two is that Terra can be manipulated using Lua as a metalanguage: for example, you could write a Lua function which produces Terra code, which is then executed. In some sense, this is like C, which has a lower-level language (C) and a corresponding high-level language which can manipulate that lower-level language (the C preprocessor). In this case, though, Lua is much more powerful and flexible than CPP, and Terra is also a smaller, simpler language than C.

It gets more powerful, though, because the Lua parts don't just have to exist at compile-time. You could use Lua at run-time to produce Terra code, which in turn can get executed immediately, producing object code specialized to a given situation or machine: for example, you might write a language, use Lua to parse it, and then convert it to Terra to produce object code which is then invoked immediately: this effectively just-in-time compiles your code. Or, you could write an algorithm in Terra with specific constants that aren't known until run-time, and then use Lua to stitch those constants in before running the algorithm: for example, to take advantage of specific machine features or parameters.

These examples also assume that you have only "compile" and "run" stages; you could also write programs with more stages: for example "compile source", "specialize for machine", and "run" could be three distinct stages. Terra/Lua would afford you the flexibility to stage your computations in this way.

andolanra··on The Evolution of a Haskell Programmer (2001)
I mean, the multiple-ways-to-do-things bit is possible in any language. Even Python, with its guiding principle that 'there's only one way to do it', would allow you to do it in different ways:

    def factorial(n):
        if n == 0:
            return 1
        else:
            return n * factorial(n-1)

    def factorial(n):
        return 1 if n == 0 else n * factorial(n-1)

    def factorial(n):
        return eval('*'.join(map(str, range(1, n+1))))

    def factorial(n):
        return reduce(lambda x, y: x * y, range(1, n+1))

    def factorial(n):
        def facts():
            n, r = 1, 1
            while True:
                r, n = n*r, n+1
                yield r
        return next(islice(facts(), n-1, None))
The difference is: historically, Haskell was an experimental language, a test-bed for trying out new and weird ideas, which meant that experimentation with style has been pretty normal thing. Haskell "culture" encouraged being clever, because that's how you found new, interesting ideas. On the other hand, Python doesn't have that legacy: most of the implementations above are non-idiomatic because they're too clever.

So yes, you can write things lots of ways in Haskell. But, if you had production code in Haskell, you wouldn't try to be clever, in the same way that you wouldn't (or shouldn't) try to be clever in production code in Python. You'd write simple, straightforward code, just like

    fact n = prod [1..n]
andolanra··on Idris, a language that will change the way you think about programming (2015)
The story, if I recall correctly, is that the programmer Edwin Brady had a previous project that was a proof engine, and lacking a suitable name for it, named after an older British children's cartoon called Ivor the Engine.[^1] When it came time to name a newer project, he decided to name it after another character from the same show: Idris, the little red Welsh dragon. This, incidentally, is why the Idris language's logo is a stylized red wing.

[^1]: Ivor the Proof Engine is here, although apparently not actively updated any more: https://github.com/edwinb/Ivor

andolanra··on The 85 ways to tie a tie
A very cool paper! But it has in fact been superseded by subsequent research: the actual number of tie-knots is much larger—at least in the tens of thousands. The insights that led to that research on top of the Fink and Mao paper are described in this essay that then uses those ideas to illustrate the idea of language-oriented computer security: https://medium.com/message/necktie-knots-formal-languages-an...

The paper itself is titled, appropriately, More ties than we thought: https://peerj.com/articles/cs-2/

andolanra··on LALRPOP, an LR(1) parser generator for Rust
PEGs can sometimes be pretty unintuitive. For example, consider the grammar

    ("a" / "aa") "a"
in a traditional BNF setting, this grammar could match the string aa or the string aaa. However, this PEG will only accept the string aa, and cannot match the string aaa.

(This is because of how backtracking works in PEGs—or, more precisely, how it doesn't work. With the input string aaa, we'll first try to match ("a" / "aa") against the input in a left-biased way, which succeeds because "a" matches. Then we'll try to match the second expression—"a"—which also matches. Now we are done with the grammar but still have the last a in the input, so the grammar fails. There were untried alternatives, but they only appeared in earlier parts of the grammar which had already 'succeeded', so we never go back and try them.)

Additionally, both LR and PEG parsers take linear time to parse a given input, but PEG/packrat parsing has much larger constant factors. On small examples, this might not be a big deal (what's 0.2 seconds compared to 0.02 seconds when loading a file?) but when doing large amounts of parsing it can definitely be a minus on the PEG/Packrat side.

andolanra··on MIT claims to have found a “language universal” that ties all languages together
Wilkins' book describes a universal language, which is not at all the same thing as linguistic universals.

Wilkins was trying to derive a language in which each word functioned as an index into a universal ontology of concepts, so that the concept represented by a word could be deduced by breaking apart the structure of the word itself. This is an interesting (if quixotic) experiment, but it's really concerned with building an a priori language.

The study of linguistic universals is the study of properties of natural languages: for example, all languages have pronouns is a linguistic universal, because it is a property that is true of all natural human languages. This is clearly not something that Wilkins was working towards: he was building a new language for the purpose of perfecting and clarifying communication. His Real Character had little—if anything—to do with analysis of the properties of natural language, and therefore also has little to do with the study of linguistic universals.

andolanra··on MIT claims to have found a “language universal” that ties all languages together
There's a hidden premise in your argument that I would argue is false, and that's that programming languages should attempt to emulate the same principles as natural languages. Programming languages and natural languages do not at all fill the same niche, and there are many cases in which natural languages optimize for things that would be bad in programming languages.

For example, natural languages are infamously redundant—for example, gender agreement between nouns and adjectives and even (in some languages) verbs—but that's because they developed so that they could be understood even if you were shouting over the wind or otherwise didn't hear part of the sentence. Programming languages have no such restrictions, and as such, optimizing a programming language for the same kind of redundancy as a natural language would lead to needless tedium like

    int x = int_addition(int 2, int 3);
but in the context of a programming language, this kind of redundancy ends up being needless bookkeeping without presenting any of the same advantages of redundancy in natural language.

That doesn't mean that your conclusions are wrong—I think some parameter orderings are better than others! But I think that's true for reasons orthogonal to the findings in this paper.

andolanra··on MIT claims to have found a “language universal” that ties all languages together
No, the implications are actually quite small. This article is a very bad pop-science summary of relatively banal linguistic research.

Linguists have studied linguistic universals for a long time, which are properties that all human languages have. For example, one could try to imagine (in the style of Borges) a language which had no nouns, and in which all sentences are formed of relationships between verbs—but no natural language has this feature: all natural languages have nouns and verbs.

There are also implicational universals, which are of the form, if [some language] has property X, then it will also have property Y, and tendencies, which are broad driving trends that might have individual exceptions. An example of the latter is that languages that place the verb at the end of the sentence usually have postpositions rather than prepositions, but this has exceptions (e.g., Latin.)

What's being studied here is a tendency in sentence structure: languages usually structure their syntax such that they can minimize the dependency length, or the distance between syntactically releated words in a sentence. This has long been hypothesized, but this paper gives evidence for it in the form of a large cross-language survey. Which is cool! But by no means does it have major implications for CS in any way. (At least, no more than any of the copious previous research on linguistic universals.)

EDIT: I should also add that this area of research is not new. In fact, linguist Joseph Greenberg published an article called 'Some universals of grammar with particular reference to the order of meaningful elements' in 1963. This is continuing research and, while good research, not particularly groundbreaking or pioneering.

andolanra··on How to compile C apps with musl and Clang
There's also Void Linux, which has musl and glibc versions of packages and offers both musl-based and glibc-based download images: http://www.voidlinux.eu/
andolanra··on Top Down Operator Precedence (1973)
If you're using something that generates a parser for you—like bison or yacc—then sure, you can express your grammar like that, and there are advantages to doing so. On the other hand, if you don't have something like that available—say, you're working in a language where nobody has written a yacc clone yet, so there's no way for you to generate a parser from a BNF description—then implementing a Pratt parser is a lot easier than implementing a parser generator.

Even if you have alternatives, there are still situations in which you might want to use a Pratt parser. It's much easier to understand the internals of this kind of parser than understand the shift/reduce rules of an LL(k) grammar, and Pratt parsers have the nice property that you can easily modify them at runtime, making it easy to switch to alternate grammars in particular contexts—e.g., directly parsing SQL within particular delimiters is a pretty trivial task that is somewhat more difficult with a BNF-style grammar.

EDIT: Actually, a better final example would be user-defined operators with arbitrary precedence and branching. There is no way of expressing this directly in a BNF-style grammar, but it is trivial with a Pratt parser.

andolanra··on Porting a NES Emulator from Go to Nim
You can have manual control over memory if you want, though. This worked the last time I looked at the language, at least:

    foo = cast[ptr Foo](alloc(sizeof(Foo)))
    # do stuff with foo
    dealloc(foo)
EDIT: Here's the documentation on the site itself. Most things are 'traced' by the GC, but by using alloc and dealloc you can work with 'untraced' (i.e. manually allocated) memory: http://nim-lang.org/0.11.0/manual.html#types-reference-and-p...
andolanra··on TrueCraft, An Open Source Implementation of Minecraft 1.7.3
There's a Rust client in the making called Hematite[1], but it currently will only allow you to move around static worlds, with no other interaction. The focus so far has been on making the rendering as close to pixel-per-pixel identical as possible: [2]

[1]: http://hematite.piston.rs/

[2]: http://imgur.com/a/bHcLD#0

andolanra··on 1ML – unifying ML into one language
The proposed OCaml implementation of modular implicits[1] considers ambiguity a compile-time error, so in that case you'd have to manually indicate which module you're passing in. (This is in contrast to Scala, in which there's an elaborate mechanism for resolving ambiguity in implicits which makes it hard to know which is being selected.)

So the OCaml implementation shouldn't make it any more difficult to discover which implicit is in use in a given context, because if an implicit is used, then it must necessarily be unique and there will be no ambiguity.

[1]: http://www.lpw25.net/ml2014.pdf

andolanra··on 1ML – unifying ML into one language
We could in fact write mkMap in Idris with very little change, and give it a proper type:

    -- This might not be the best/cleanest way of writing it, as my
    -- Idris is a little rusty, but this will work:
    mkMap : (size: Int) -> (if size > threshold then HashMap else TreeMap)
    mkMap size with (size > threshold)
      | True  = newHashMap
      | False = newTreeMap
So yes, although again, other tradeoffs are made to allow this kind of radical expressiveness.
andolanra··on 1ML – unifying ML into one language
That type means something slightly different: (Map m) => Int -> m doesn't mean that it returns some Map type, it means it returns any Map type. We could write a function of that signature, but that would imply that the caller/context would choose what type of Map it returns (and so it would not depend on the integer argument.)

Think about what it means if a type variable has no typeclass constraint: the type t isn't just a specific unknown type, it's literally any type. Similarly, C t => t isn't a specific unknown instance of a typeclass, it's any instance of that typeclass. If we tell Haskell that we're returning an instance C t => t and then try to give some concrete type, Haskell won't allow it, because it wants that type to encompass any possible type that implements C, not just the one we happened to use.

One way of making the above code work in Haskell is to use an existential type, which expresses that we're talking about some (not any) map type, but we'd have to wrap it inside a different constructor:

    -- this expresses that a SomeMap constructor contains some kind
    -- if Map, but we can't tell which one:
    data SomeMap = SomeMap (forall m. Map m => m)

    -- We can now express this by hiding the choice of Map inside the
    -- SomeMap type:
    mkMap :: Int -> SomeMap
    mkMap size | size > threshold = SomeMap newHashMap
               | otheriwse        = SomeMap newTreeMap
which is, again, a solution with some advantages and some disadvantages.
andolanra··on 1ML – unifying ML into one language
There are very much ways of expressing that computation in SML—or in Haskell or other languages—but not in the language of modules. Haskell typeclasses would have a similar problem. Consider the following pseudocode:

    class Map m where {- some implementation -}
    
    instance Map HashMap where {- ... -}
    instance Map TreeMap where {- ... -}

    mkMap :: Int -> {- ??? -}
    mkMap size | size > threshold = newHashMap
               | otherwise        = newTreeMap
What is the type of mkMap? It won't actually type-check in Haskell. It can't be (Map m) => m, because it needs to have a concrete type. We could do some kind of type-level work, relect the size variable into the type level, and have a type family that decides whether the resulting type is a HashMap or a TreeMap—but that has the same problem as the OCaml example, where we're using a different language (the language of type-level computation) to talk about something that'd be simple with value-level programming.

One place where you could write this easily is in a dynamically typed language:

    def mkMap(size):
        if size > threshold:
            return HashMap()
        else:
            return TreeMap()
That is exactly why this kind of research is interesting: we'd like to capture the flexibility of idioms that dynamic languages can sometimes afford us, with the extra safety and security guarantees of a static type system!
andolanra··on 1ML – unifying ML into one language
One of the classic motivating examples (which is addressed in the 1ML paper) goes like this:

Both trees and hash tables can be used to implement map-like data structures. You could, in ML, have an abstract signature for Map types that gets implemented sometimes by a concrete TreeMap implementation and sometimes by a concrete HashMap implementation. HashMap would be a better choice if the expected number of entries is larger, and the TreeMap would be better if the expected number of entries is smaller, so what we'd like to do is write something like

    module Map = if size > threshold then HashMap else TreeMap
so that we choose what concrete implementation we want at runtime—but we can't really do that, because the language we use to talk about modules in ML is distinct from the language we use to talk about values. That is to say, the size > threshold part can't coexist in the same expression with the HashMap and TreeMap part. Some MLs have added the ability to wrap modules in values, so you can write it this in OCaml:

    module Map = (val (if size > threshold
                         then (module HashMap : MAP)
                         else (module TreeMap : MAP))) : MAP
but it's a bit awkward because of the explicit moving-back-and-forth between value-level and module-level, and the interaction between the two languages has some rough edges (which the paper explains more thoroughly, if you're interested.)

The motivation for 1ML is that we'd like to use the same language to talk about both modules and values. That way, we could write the first, simpler definition without having to worry about the fact that we're manipulating distinct 'things'. Of course, there are other tradeoffs involved in the 1ML solution, but it's an interesting, compelling experiment.

andolanra··on Absolute Beginner's Guide to Emacs (2012)
I'd argue that your "spectrum" misses where emacs really shines: nobody really bothers to reconfigure Eclipse or Netbeans as their mail client or web browser, whereas this is not entirely unusual with emacs. This is because emacs has both a simpler set of underlying elements and a richer extension language when compared with something like Eclipse. This makes it IDE-like, but much more expressive and elaborate: there are things you can do with emacs that you could only dream of doing in things like Eclipse.

Furthermore, writing extensions for emacs is much more pleasant than writing extensions for Eclipse, and is done much more widely. And, emacs has been around long enough that you have literally decades worth of extensions already available to you. Additionally, emacs is used widely enough that people are quick to add emacs support for new things: if I pick up a new esoteric language tomorrow, I can be 99% sure that there's no Eclipse support for it, but I can be 100% sure that there's already an emacs mode for it and it's probably on the emacs package manager already, to boot.

All this is both a plus and a minus, in some ways: learning emacs is probably not worth it unless you're willing to put the time and effort into building up your emacs configuration into something IDE-like, but if that's what you want to do, then emacs can do truly amazing things. So yes, what you said rings more or less true for vanilla emacs, but you're radically underselling emacs as a platform for building better things.

andolanra··on Harry Potter and the Methods of Rationality finished today
This is the kind of thing which could very easily turn into a flame war, and is much further off-topic. I'm not interested in that kind of argument right now, so all I will say in this thread is this:

My personal experience with Less Wrong-style rationalism, to simplify the situation aggressively, is that it has a core of good, useful tools (Bayesian reasoning, strict positivism, utilitarianism) that I have no problem with. However, when pushed too far, those tools tend to break down—but the rationalist answer to that breakdown is all too often to embrace the model and discount the reality. This general refusal to regard their core tools with suspicion results in beliefs which are paradoxically irrational: when faced with e.g., utilitarianism condoning torture to prevent mild discomfort, the rationalist response is not, "Perhaps human experience does not map straightforwardly to integers—we should re-examine our tools," but rather, "As our mathematical tools are of course correct, we must believe in this conclusion." This belief in math-over-matter is a major part (though not the only factor) in my skepticism towards the kind of rationalism promoted by Less Wrong.

andolanra··on Harry Potter and the Methods of Rationality finished today
I read well through chapter 70. I did imply that scientific investigation shows up a little, after all! I agree that the line people gave me wasn't correct, but I've heard that line enough that I felt it was appropriate to dispel that particular notion.

Perhaps also germane is that I am not personally a believer in Less Wrong-style rationality, and so the intellectual content of the work was not relevant to me except in the detached way that philosophical or political or religious schools can be interesting to non-adherents (which is one reason I read as much as I did.) Whether the story accomplishes its actual goal, then, is something I can't judge, but I can say that, as a non-rationalist (irrationalist?) I didn't find it to be a good or engaging story.

But as I said in my previous comment, this is my own reaction, and I include it for informative reasons, not because I think others should necessarily share it!

andolanra··on Harry Potter and the Methods of Rationality finished today
I have been following someone's critical chapter-by-chapter criticism of HPMOR for some time now, which might be illustrative. It is admittedly quite long: http://su3su2u1.tumblr.com/tagged/Hariezer-Yudotter/chrono

Among other things, I've often seen people try to sell HPMOR as, "Harry Potter fanfiction in which Harry applies the scientific method to the magical world of Harry Potter!" And that shows up a little [^1] but is by and large not the content of the work. Harry does very few experiments to verify his hypotheses and is actually a broadly incurious character. For example: Harry is nominally interested in eliminating death, but never once investigates the many magical mechanisms which seem to eliminate death, preferring to just talk about it instead. Similarly, he comes up with hypotheses as to how magic works, but never bothers to investigate them beyond speculation.

Additionally, a lot of the "solutions" to problems Harry has are relatively unsatisfying: Harry often circumvents a problem by "clever" applications of the rules, but because the rules of magic as given both in Rowling and in Yudkowsky are ill-defined and even self-contradictory, this seems less clever and more like arbitrary author fiat. Harry is also given a small time machine early on in the plot, and so more often than not, the solution to his problems is, "Use the time-turner again."

Finally, I personally found the writing style to be generally in need of editing—not terrible but certainly not polished—but I consider that to be a smaller problem than the above plot-related issues. EDIT: All this doesn't mean that you shouldn't like it! These are just problems that I had with the work.

[^1]: The bit where Harry tries to experimentally prove that P=NP is probably my favorite part of the entire thing.

andolanra··on Lisp in 3 words
There's a lambda-calculus-like core to Lisps, but there's enough on top that I'm not comfortable saying that Lisp implementations are "just the lambda calculus." As for indentation-based syntax, there is a Scheme SRFI[^1] that specifies an indentation-based syntax, although I'm not sure how many Schemes actually ship with implementations.

[^1]: Various extensions to Scheme are proposed as numbered SRFIs; the extension in question is SRFI 49, as defined by http://srfi.schemers.org/srfi-49/srfi-49.html

andolanra··on Debian developer prompted to revisit FreeBSD after 20 years
I don't think there were too many people in that debate who were dissatisfied with the idea of a new init system. People were dissatisfied with systemd specifically, because of various architectural choices that it made. The fact that FreeBSD might adopt a new init doesn't in itself mean that those people will be scared off.
andolanra··on C99 tricks
I see this used a lot with enums to make a kind of 'homogeneous struct' where all the members have the same type:

    enum fields = { x, y, z };
    int point[] = {
      [x] = 1,
      [y] = 2,
      [z] = 3
    };
This is used pretty extensively in the QEMU codebase, which is where I first learned it.
andolanra··on A complete rewrite of wiki as a single page application
That's already how it works. You could run your own node and share information back and forth with other nodes, or you could use an account on an existing node. This is clearly the case: if you go to the C2 Federated Wiki, you'll note the Login button.
andolanra··on A complete rewrite of wiki as a single page application
It's all still there: http://c2.com/cgi/wiki

I assume they'll move it over to the Federated wiki at some point, but you can still view everything on the old wiki.

andolanra··on A complete rewrite of wiki as a single page application
This is the (admittedly somewhat long) transcription of a talk I use to introduce people to the idea: http://hapgood.us/2014/11/06/federated-education-new-directi...

The elevator pitch for tech-minded people is that wikis are to SVN as federated wikis are to git. Instead of a shared wiki that people modify, each user has their own wiki which consists of both pages they've made or forked, so information propagates back and forth between users. It's a really compelling idea and I hope they can make it work.

← PreviousPage 4 of 10Next →