Skip to content

Instantly share code, notes, and snippets.

@FranchuFranchu
Created December 31, 2022 02:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FranchuFranchu/fc6ab0dbe0da01b75fb86700b1d722c0 to your computer and use it in GitHub Desktop.
Save FranchuFranchu/fc6ab0dbe0da01b75fb86700b1d722c0 to your computer and use it in GitHub Desktop.
an idea

This is a silly idea for programming language I had. I didn't give it much thought, and the syntax & edge case rules are just a placeholder.

The only structured data type is the "record".

A record is a key-value mapping. It can also be typed.

MyRecord = (
	value: Int = 0,
	other_value = value + 24
)

MyRecord.value # returns 0
MyRecord(value = 10).other_value # returns 34
MyRecord(value = 10)(value = 20).value # returns 20

Since "calling" a record returns a record too, chained calls override the values.

Records are also types. A record instance_record is an instance of another type_record if and only if:

for all field names k in the type_record:

  • if instance_record.k is not set, and type_record.k is not set.
    • typeof instance_record.k is a subtype of (or equal to) type_record.k
  • if instance_record.k is set to a value
    • typeof type_record.k is the type of the value.

Here is an example:

Person = (
	age: Int,
	name: String
)

Person(age = 23, name = "Bob") # an instance of Person, because 23: Int and "Bob": String

The syntax used for records can also be used for "functions".

AgePerson = (
	person: Person,
	change_person = person(age = person.age + 1),
	return change_person
)

AgePerson(person = Person(age = 23)).age # Returns 24

The magic keyword here is return, which makes the code block return a field in the record instead of the record itself.

The return magical keyword is not really necessary for the language to be complete; it's just much more ergonomic than doing AgePerson(person = person).changed_person.

Return also makes it necesary to add a special rule for typing, which is that the type of "function" records has a "return" field which specifies what type the function returns

# Church-encoded booleans

Bool.true = (
	t: Type
	true: t
	false: t
	return true
)

Bool.false = (
	t: Type
	true: t
	false: t
	return false
)

Bool = (
	t: Type
	true: t
	false: t
	return: t
)
# false: t and Bool.return = t, and since Bool.false returns an instance of t then this is true:
Bool.false : Bool

Please share your thoughts and ask questions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment