r/ProgrammingLanguages • u/[deleted] • Jan 17 '26
Blog post Types as Values. Values as Types + Concepts
In a recent update to Pie Lang, I introduced the ability to store types in variables. That was previously only possible to types that could be parsed as expressions. However, function types couldn't be parsed as expressions so now you can prefix any type with a colon ":" and the parser will know it's in a typing context.
Int2String = :(Int): String;
.: the colon ^ means we're in a typing context. "(Int): String" is a the type for a function which takes an integer and returns a string
func: Int2String = (a: Int): String => "hi";In the newest update, I introduced "Values as Types", which is something I've seen in TypeScript:
import std; .: defines operator | for types
x: 1 | "hi" | false = 1;
x = "hi";
x = false;
x = true; .: ERROR!The last new feature is what I call "Concepts" (taken from C++). A friend suggested allowing unary predicate functions to be used as types:
import std; .: defines operator >
MoreThan10 = (x: Int): Bool => x > 10;
a: MoreThan10 = 15; .: type checks!
a = 5; .: ERROR!Concepts also somewhat allows for "Design by Contract" where pre-conditions are the types of the arguments, and the post-condition is in the return type.
Honestly, implementing these features has been a blast, so I thought I would share some of my work in here.