Hacker Newsnew | past | comments | ask | show | jobs | submit | gavinlynch's commentslogin

why would you want to view a programming language algebraically?


It lets you reuse your existing knowledge about algebra to transform programs. For example if you have a data type that has two different cases (= sum) each of which has a bunch of fields (= factors in a product) some of which are shared (= common factors in a sum of products) then you can literally factor them out, just like you can factor A * B * C + A * D * C into A * (B + D) * C.


Conjunction and disjunction are more apt anologies that have the same properties. There is also no division types while subtraction is used very rarely.


I didn't think to call it that at the time, but I think that I came across a division type in react-redux the other day: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/8f8f...

Playing with that a little, if adding a property to an interface is a product, eg:

    interface Foo {
        foo: string;
        bar: number;
    }
where Foo is a product of string and number, then removing a property from an interface is division:

    type Diff<T extends string, U extends string> = ({ [P in T]: P } & { [P in U]: never } & { [x: string]: never })[T];
    type Omit<T, K extends keyof T> = Pick<T, Diff<keyof T, K>>;

    interface Foo {
        foo: string;
        bar: number;
    }

    interface Bar {
        bar: number;
    }

    type Out = Omit<Foo, keyof Bar>;
the output type Out is equivalent to:

    interface Out {
        foo: string;
    }
or phrasing it another way:

    Out = Foo / Bar = (string * number) / number = string
I can't think what a 1/number type would be used for other than to remove number from a a T*number, in other words I can't think what a rational type would be used for unless it simplified down to a "normal" type. But I wouldn't like to bet that there's no other use :-)


What is the set theory intuition of that? If product is intersection, division is...?


Product is not intersection. The equivalent to product types in set theory is the Cartesian product ( https://en.wikipedia.org/wiki/Cartesian_product ).

The closest thing to a division would be a quotient set ( https://en.wikipedia.org/wiki/Quotient_set ), but there you're dividing by an equivalence relation. It is however possible to define an equivalence that undoes set multiplication: (A × B)/~ ≅ A if (a₁, b₁) ~ (a₂, b₂) holds iff a₁ = a₂, ignoring the other component.


That isn’t how product (intersection) types work in typescript. If we are talking about typescript, of course.


Product and intersection are different things in TypeScript, as well. The product of string and number would be a type like { first: string; second: number }, which combines two different values into one; whereas the intersection string & number is the type of all values that are both strings and numbers.


Right, but if we are going to call union types as sum types, why aren’t interesection types called as product types? Anyways, this is why the whole sum type thing breaks down and Union is more apt, since we can describe A|B and A&B using the same terminology family.


A | B and A + B are only "the same" (but not identical) if A and B are disjoint (i.e. there is no value that is in both types). That's why + is also called disjoint union. You can simulate + with | by introducing artificial tags to make A and B disjoint, but in the end they are different operations. TypeScript doesn't really have first-class support for sum types because it needs to remain interoperable with JavaScript, so this simulation is the closest you are going to get.


I agree, so it really isn’t an example of the popularity of sum typing. Typescript does have support for user-supplied tagging, so you can also approximate it to some extent.


Yea, support isn't first class. When I was learning to use union types in TypeScript, initially I wrote custom type guards to distinguish them, using any property that was unique to a particular constituent type to differentiate them.

Nowadays I consider that a mistake, and all unions have a discriminator property, and there is no need for custom type guards (exceptions would be when writing .d.ts files for JS that uses them untagged, that sort of thing) since it makes the code much more explicit.


> Conjunction and disjunction are more apt anologies that have the same properties.

Conjunction and disjunction also have other properties, like idempotence: A /\ A = A, which by analogy would suggest that a tuple of two integers is the same as a single integer. Similarly, A \/ A = A, which is exactly the problem mentioned by the featured article that is the difference between union types and proper sum types (aka tagged union types).

So while sum and product may not be great analogies, conjunction and disjunction seem worse.


A lot of academic programming language research is an outgrowth of mathematics, so it uses the language of mathematics.

E.G "boolean" dates back to George Boole, The Mathematical Analysis of Logic (1847)

https://en.wikipedia.org/wiki/Boolean_algebra#History

and "lambda" to Alonzo Church in the 1930s

https://en.wikipedia.org/wiki/Lambda_calculus



This would be more useful and more upvoteable if you had provided some text for context.

TLDR: If you interpret sum types as + and product types (tuples/structs/objects) as *, type definitions can be read as polynomials. Recursive type definitions, like for linked lists, can be read as recurrence equations. If you do some calculus over these things and compute the derivative of these type formulas, you get back something meaningful: The formula corresponding to the type's Zipper (https://en.wikipedia.org/wiki/Zipper_(data_structure)), a data structure for efficiently traversing and modifying functional data structures.

I like Chris Taylor's series of posts on this topic, as well as this shorter one: https://codewords.recurse.com/issues/three/algebra-and-calcu...


This is what leads to things like monads appearing as programming constructs; they provide neat abstractions which allow you to reason about code at a higher level than you otherwise could.


hey bbitmaster :)

i remember when you were creating that debugger, long time no see. (what's it been, a decade?) Fceuxd was always the best romhacking emulator, gotta love those conditional break points!

this takes me back to the old days of beta testing, and hanging in #rom-hacking on irc hope you're well :)


Hey Gavin. Of course I remember you, it's been ages but great to hear from you. I would take this to PM but Hacker News doesn't seem to offer such a feature. I currently work in the bay area, in Machine Learning (I only mention it in case you happen to reside in the bay area). Anyway, feel free to e-mail me at my username at gmail.

Good times :-)


I feel this is a great time to point out that Plato disliked a lot of democracy.


VML was great when you wanted to do canvas-like things with IE6 Back In The Day: http://excanvas.sourceforge.net/

I had some visual analytics tools that ran "canvas" on IE6 in 2008 thanks to VML. Never did pure VML but it was a nice crutch to have if you wanted to get very experimental and very cross-browser.


Well, this is the future of the music industry. It's an incredibly sound ivestment to increase the buy-in of major players to increase the overall long-term viability of the product. It's kind of a "duh", but to be fair many companies miss the "duh"


I find this specious: What modern web app isn't minifying/concatenating it's Javascript and CSS source? All of your concerns are easily remedied via a proper build procedure. And we're talking about, in relative terms, miniscule amounts of data for the web. 33 kb? C'mon now.


> I find this specious: What modern web app isn't minifying/concatenating it's Javascript and CSS source?

In that case, you should learn more about web performance: minification is a useful tool but it's not magic. If you add code to a bundle, you're almost certainly transferring too much data for the initial request — which increases the time before anything can run — and making caching less efficient because any change to your JavaScript invalidates the entire cached object; if you serve it separately, caching works better but you'll incur the latency cost multiple times. Every site has to balance these factors against user capabilities and the site performance targets.

To illustrate why you're being entirely too cavalier, consider Ilya Grigorik's excellent Velocity 2013 presentation detailing exactly what it takes to reliably deliver a rendered webpage in 1 second on mobile:

https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&c...

Note that his performance target is roughly 14KB transfer to deal with the way 3G performs in the real world. If you were thinking about including jQuery, you just blew that budget twice over: a fully compressed, gzipped copy of jQuery 2.0.2 is 29KB. If you concatenated everything, you not only blew your transfer budget but you ensured that none of your JavaScript, even the parts which are entirely self-contained, executes within that performance target.

The point isn't that CDNs aren't useful (they're great), asset packaging isn't good (it's a key tool), or even that jQuery is bloated, but rather that good engineers make decisions based on their performance goals and actual measured user performance rather than flippantly saying “We use a CDN so the site will be fast!” (contra: healthcare.gov) or “everything is minified, so it'll be fast”.


Without making a judgement call on the virtue of his of actions: I consider myself very skeptical of the notion that this administration, which has cracked down on whistle-blowers/leakers as much (or more) than any other, is about to offer anything other than the "full weight of Justice" on Snowden.

I enjoyed Philip Bump's piece from the Atlantic about this: "Why Does CBS Keep Asking Its Ridiculous Amnesty Question About Snowden?"

http://www.thewire.com/politics/2013/12/why-does-cbs-keep-as...

What can Snowden promise them, anyway, that they would make this deal? The toothpaste is out of the tube.


> What can Snowden promise them, anyway, that they would make this deal? The toothpaste is out of the tube.

My understanding is that he has actually been quite a bit more judicious than Manning about what he has released, putting out stuff that clearly shows what the NSA is doing wrong. I get the impression that he does have more material that could go out but he doesn't feel really needs to be public, as a bargaining chip.


> My understanding is that he has actually been quite a bit more judicious than Manning about what he has released, putting out stuff that clearly shows what the NSA is doing wrong. I get the impression that he does have more material that could go out but he doesn't feel really needs to be public, as a bargaining chip.

I believe he's claimed to have gotten rid of all materials prior to going to Russia. They're in the hands of the team of journalists distributed around the world.


> I believe he's claimed to have gotten rid of all materials prior to going to Russia.

This was in response to the question about this data accidentally falling into wrong hands. He said he was very confident that nothing was stolen copied or accessed during his stay in Hong Kong, and that he completely wiped his harddisk before going to Russia.

This doesn't mean that this data does not exist, anywhere, as a bargaining chip. Just that it is not present with him, on a physical storage medium in Russia.


This was my impression as well.


> My understanding is that he has actually been quite a bit more judicious than Manning about what he has released, putting out stuff that clearly shows what the NSA is doing wrong.

That was his claim, yes, but it's quite incorrect.

Various journalists have the data now and are piecing through it, not Snowden, but things like details of Chinese hacking or tapping into Merkel or Medvedev's phone calls are not violations of U.S. civil liberties and can hardly be said to have been judicious disclosures.

In that regard Manning actually ends up with a better case IMHO; Snowden claimed to have specifically looked at and identified every piece of data he took as requiring disclosure (although taking 58,000-1,000,000+ pieces in a year with a full-time job to do would tend to argue against being 'selective'), so any areas where Snowden leaked something that was only vital to national security happened after he specifically cleared it.

Manning, on the other hand, specifically released a few things but other than that let loose a bunch of data she never quite scanned through. This was definitely negligent, but doesn't seem to have been malicious.


What can Snowden promise them, anyway, that they would make this deal?

They don't know exactly how much he has and the government has some interest in securing the data that he hasn't released.


I don't think covering up something else is what the US should be looking at. If the US were to pardon snowden, it would be to turn a corner (or if you are super cynical, look like your turning a corner) on domestic spying.

Recall that nelson Mandela was classified as a terrorist by the CIA for quite a while. and now his funeral was attended by numerous presidents and ex presidents. I'm NOT saying snowden == Mandela, but that a change in language and a pardon would be to turn a corner on this issue.


Assuredly, like most/anything in life, repetition and dedication will be your regex salvation.

Tools such as this are shortcuts for newcomers to grok the various operators rapidly. I think they are very worthwhile.


I love these types of things. Kudos to the author.

This one in particular reminds me of a tool I've always found useful. It's an interactive Regex builder just like the one linked in the OP. I would say it's got some additional compelling features: like mouse-over breakdowns of each expression as you build it, a handy reference list as well, but also a community concept and saved expressions. Really, I've never found anything better. My only complaint is that it's flash-based, but it's an amazing tool, so can't really complain too much.

http://gskinner.com/RegExr/


I wonder what is preventing Stallman from doing it himself? It is, after all, open source.


Time. He is quite busy with conferences and FSF stuff.


Time? It's been 25 years.


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: