#great-lounge Sunday 7 August 2022
30 messages3 people
- J00:05I was watching a youtube video about functional programming that was explaining the inspirations for it, and it mentioned that mathematics had a similar problem00:05He alluded that functional programming was that solution but for programming00:06And I thought to myself, hey, if sets worked so well for mathematics, then why couldn't it work for programming?
- A
- J
Person = <name, age, height, talk, die> ∀name∈String ∀age∈R ∀height∈Height ∀talk∈Λ ∀die∈Λ createPerson={<<name, age, height> < name age height say={<words < print(name + ": " + words) >>} sayRepeatedly={<words < for(x∈R:0<x<10 {<x < print(name + ": " + words) >>}) >>} die={<{} < name.talk("blegh") print(name + " died") >>} >>}00:07Example code00:09So in set theory, a function is represented as a set of ordered pairs. For example,f(x) = x + 2is represented by{... <0, 2> <1, 3> <2, 5> ...}00:09An ordered pair is represented by{{a}{a, b}}00:10So ideally, in an interpreter for this language,{{a}{a,b}}would be treated the same as<a, b>00:10So you could rewrite the above code in a very cursed way if you really wanted to00:15createPerson={{{{{name {name age}} {{name {name age}} height}}} {{{name {name age}} {{name {name age}} height}} name age height say={{{words} {words { print(name + ": " + words) }}} sayRepeatedly={{{words} {words { for(x∈R:0<x<10 {{{x} {x { print(name + ": " + words) }}}}) }}}} die={{{{}} {{} { {name.talk("blegh")} {name.talk("blegh") print(name + " died")} }}}} }}}00:15There's definitely a mismatched bracket somewhere in there00:18Person = {{{{name {name age}} {{name, {name age}} height}} {{{name {name age}} {{name, {name age}} height}} talk}} {{{{name {name age}} {{name, {name age}} height}} {{{name {name age}} {{name, {name age}} height}} talk}} die}} ∀name∈String ∀age∈R ∀height∈Height ∀talk∈Λ ∀die∈Λ00:18I know what you're thinking: What's the advantage to this?00:18Uhhh00:18Ummm]00:19Cause um it's so better00:19and math00:20Feel free to stop that timer now lol00:22I'm pretty sure this language covers all the things you need for a language. Maybe I'm missing some00:23Oh and here's calling that constructor and calling the say method:createPerson(<"bob" 38 {5 9}>) .say("Hello!")00:23Parentheses optional00:24The language makes use of 5 unicode characters:∀ ∈ ∪ ∩ Λ00:25Everything in the language is a set. It is the only primitive00:26Classes are sets, types are sets, functions are sets00:26for, if, while are sets00:27And there is no mutability00:29The great thing about sets is that you can represent an open bracket as a 0 and a close bracket as a 1, meaning space efficiency! - K
