11 ms·
The λ-Cube
- 7373737373 5y agoHere's a website where you can try a few of these systems: https://typezoo.netlify.app/ https://typezoo.netlify.app/
- ogogmad 5y agoThe syntax part seems to be missing most of the type constructors of Martin Lof Type Theory, with no apparent ways of expressing them: - Dependent sum - Cartesian product - Disjoint union [edit] More here: https://en.wikipedia.org/wiki/Calculus_of_constructions https://en.wikipedia.org/wiki/Calculus_of_constructions Turns out they can be expressed after all.
- remexre 5y agoChurch constructions? - Dependent sum Sigma A (\x -> B) = (C : *) -> ((x : A) -> B x -> C) -> C - Cartesian product Pair A B = (i : Bool) -> (if i then B else A) - Disjoint union Sum A B = (C : *) -> (A -> B -> C) -> C EDIT: Ah, started writing before you edited; yeah, (with an expressive enough type system) lambda's all you need
- atennapel 5y agoYour `Sum` is actually a `Pair` as well :). Should be: ``` Sum A B = (C : *) -> (A -> C) -> (B -> C) -> C ``` Note that in the calculus of constructions you can do these Church encodings of datatypes but you cannot derive an induction principle for these (only non-dependent folds). For example you cannot write a `snd` for the `Sigma` above. As you allude to, you need a more expressive type system to derive induction principles (for example "Self types") for lambda encodings.
- azdavis 5y agoI actually wrote a bit about this on my website: https://azdavis.net/posts/lambda-cube/ https://azdavis.net/posts/lambda-cube/ I’ve been using my website as a way to practice writing, so please let me know what you think.
- kinow 5y agoGreat post! I was going to share this one on the r/functionalprogramming subreddit when I found yours. A lot easier to read, and helps reading the Wikiversity afterwards. Thanks!
- azdavis 5y agoWow thanks! Never had my stuff shared out before to my knowledge but I appreciate it! I’ll take a look :D
- joshspankit 5y agoNo comments on the writing, but one thing to add: the syntax highlights for code get lost a bit. I would see them better either if they were a lighter black (aka dark grey), or had a different background than the rest of the text.
- bendbro 5y agoI second a higher contrast background/font color. Overall I like the minimal design. It might work to add some horizontal lines to break up sections
- azdavis 5y agoThanks! I updated it and replied to the parent comment.
- azdavis 5y agoDo you mean the inline code or code blocks? In any case, I tweaked the background to be more different from the page background (in both light and dark mode) and also gave inline code that same background. Does that help? https://github.com/azdavis/azdavis.net/commit/55199593abfb6eca9c0c9d542a224ae4cc81e2bd https://github.com/azdavis/azdavis.net/commit/55199593abfb6e...
- joshspankit 5y ago
- neilkakkar 5y agoAsking because I see something that's a lot of mappings with zero context: Why/ for what is the Lambda-Cube useful?
- JadeNB 5y agoI think it's useful mostly as a sort of Linnæan classification device—it's a lot easier to compare different type systems by placing them on a 'standard' cube, than by choosing ad hoc points of comparison.
- viewfromafar 5y agoType theories are formal logic languages. People use formal logic for all sorts of things but mathematics has the longest history. This is where people first defined formal languages and assigned meaning (mathematical meaning.) Starting from simply typed lambda calculus ("simple type theory", also "higher order logic"), one can make various extensions that make the logic language more expressive. The lambda cube is a way to systematically organize the space of type theories. Interestingly, the theory has become very relevant for type systems of normal programming languages. Milner invented ML as "meta language" for helping with logic and theorem proving, but it was used widely and today everyone expects generics to work more or less as in System F polymorphic lambda calculus.
- amw-zero 5y agoThe question was ‘why is the lambda cube useful?’ This answer was: ‘Assigning mathematical meaning.’ This is why people think these concepts aren’t useful, because this was a lot of words without any practical example of what it would be used for. Here’s a practical example: there are type systems in the lambda cube that allow us to statically check that a list has a certain length. That means a compiler can prevent an out of bounds access error, without human intervention. I have written code that crashes because of an out of bounds access, so the idea is interesting to me.
- guerrilla 5y ago> This answer was: > ‘Assigning mathematical meaning.’ No, you misread. The answer was > The lambda cube is a way to systematically organize the space of type theories. All of this was already meaningful before the lambda cube. The cube just organizes what we knew in a systematic way. It shows the relationships between the various systems that exist when they are differentiated on the features that describe their expressive power.
- wlib 5y agoSomewhat unrelated to this link, but I really think that it’s interesting how much effort we put into the theory side of languages/types - with almost no one in industry applying these lessons. The essence of this is just something along the lines of “What if we unified values with types, so we could have more useful type checking?” We have billions of dollars being spent and thousands of smart people working for decades, who don’t even get to use a proper type system - forget about statically-checked polymorphism or dependent typing. It’s not even as if we lost the ball, we’re running in the wrong direction. It’s almost trivial to bolt on gradual typing to a language. It’s also not too hard to retrofit dependent types (just don’t bother with Turing-incompleteness). The whole point of these type systems is to better model systems, so why not go the extensible route of letting anyone hook into the “type checking” phase? Import affine types (that decades old thing that got rust popular); write your own domain-specific checker, even. It’s so frustrating to see how beautiful ideas just die because we feel comfortable the way things are now. Maybe language was the wrong abstraction to begin with. Sorry to derail, but this feels like the only path to truly popularize the lambda cube as a concept.
- ogogmad 5y agoType theory has uses outside programming. It can be used to make constructive logic rigorous, which was in fact Martin Lof's original use for it.
- wlib 5y agoI’m aware of math being entirely useful outside of programming - my little rant is more about how little programming is inspired by math
- exdsq 5y agoI've used Haskell for 18 months in a professional setting. I prefer C++. Grass is always greener - having endless abstractions to be mathsy becomes a real pain when you're trying to build real products.
- black_knight 5y ago
- viewfromafar 5y agoFor anyone who wants to dive deeper, this a good series of short video lectures pulled together by students of TU Berlin that introduces this topic: https://youtube.com/playlist?list=PLNwzBl6BGLwOKBFVbvp-GFjAA_ESZ--q4 https://youtube.com/playlist?list=PLNwzBl6BGLwOKBFVbvp-GFjAA...
- vilhelm_s 5y agoCut out and assemble yourself: https://www.irisa.fr/lande/ridoux/LPAZ/node47.html https://www.irisa.fr/lande/ridoux/LPAZ/node47.html
- dataangel 5y agoCan anyone ELI5 the difference between dependent types and what Rust calls const generics and what C++ calls non-type template parameters? If I have a type that is templates/generic on an integer value, e.g. ‘MyType<3>’ is that a dependent type?
- codebje 5y agoA dependent type is a function from a value to a type - where a value is a runtime value, not a compile time constant. Can you do 'MyType<n> foo(int n) {...}' ?
- drdeca 5y agoIf that 3 can be decided at runtime rather than at compile time, yes. Like, if I can have a type Array<Type,Length> and have a function f which has as its input type Int, with the name of the input variable being n, and as its return type Array<Bool,n> and when you give the return value to something else, it checks (at compile time) that the length of the array (i.e. , n ) matches what the other thing is expecting, that would be using dependent types.
- steveklabnik 5y agoThey're subsets of true dependent types, in my understanding. This is because they can only do this at compile time, not runtime. There's no way to say, get a number over stdin, put it in a variable n, and then instantiate MyType<n> with that variable. You can with true dependent types.
- stkdump 5y agoYou could do this with the factory pattern, applied to a template type. Though, if you would do this for the whole range of say, an int, you would probably blow up the compiler. How is that done in languages that do support this? Or does it require shipping the compiler, so that you can run the compiler at runtime?
- steveklabnik 5y ago
- smitty1e 5y agoIs there a symbology primer for the lay reader who finds the Type Theory table at the bottom a trifle dense?
- mdm12 5y agoYou, my friend, are diving into the realm of formal semantics for programming languages. Benjamin Pierce's Types and Programming Languages is an excellent reference, but it is not for the faint of heart.
- deleted 5y ago[deleted]
- abeppu 5y agoMaybe a twist on the "why is this useful" question ... Users of lisp often are enthusiastic about the idea that lisp is at its core a minimal wrapper around the untyped lambda calculus (e.g. plus naming, primitive values and operations, etc). Why do we not generally see languages which are minimal wrappers around these typed lambda calculi? Perhaps intermediate languages are built closely around these formal systems (e.g. I'm aware that Haskell Core is closely based around System FC), but languages which are intended for human authors and readers seem to introduce a lot of extra machinery. Why is that? One guess is that lisps cope with being minimal through use of macros and metaprogramming, it's difficult for a typed language to support that level of metaprogramming while maintaining the various guarantees that one wants from such a system.
- Zababa 5y ago> Why do we not generally see languages which are minimal wrappers around these typed lambda calculi? If you add parametric polymorphism, you're not far from ML, which lives on these days as Standard ML and somewhat through OCaml.
- shakna 5y ago> One guess is that lisps cope with being minimal through use of macros and metaprogramming, it's difficult for a typed language to support that level of metaprogramming while maintaining the various guarantees that one wants from such a system. Difficult, but certainly not impossible [0]. [0] https://cakeml.org/ https://cakeml.org/
- somewhereoutth 5y agoMy understanding is that Javascript (for all its woes) is more nearly the untyped lambda calculus. For example, you can do: my_list.map(e=>(a=>some_transform(a)+some_other(a))(sanitize(e))) or otherwise in LC: (map my_list (\e (\a (add (some_transform a) (some_other a))) (sanitize e))) Perhaps much of the power or even the success of javascript is that, in its own way, it brings us closer to the light. It could be, with progressive typing systems (as attempted by TypeScript), with a coherent manner of synthesizing ground types (in the LC itself, subject to a kind of logical 'shield' as we might understand from Arduino), and a sensible conceptual model for dealing with side effects / threading, we could find a pure way of programmatic expression - allowing the model within our minds becomes reified once and for all. Or, it could be that this ideal is unreachable in a fundamental sense.
- galaxyLogic 5y agoSo what is a "type", according to this formalism? Isn't it a function from any value you can create in a programming language to Boolean result which tells if that value is a member of that type?