Skip to content

Instantly share code, notes, and snippets.

@neilw4
Last active November 29, 2015 17:31
Show Gist options
  • Save neilw4/0d718c50a8a567e0922d to your computer and use it in GitHub Desktop.
Save neilw4/0d718c50a8a567e0922d to your computer and use it in GitHub Desktop.
# language will be fully statically typed with no type signatures and compiled to something fast (probably LLVM)
myObj = 5
# 1st class functions are defined like objects
myFn = (arg1):
return arg1 + 2
# functions with no explicit return type will return an object with all of the members in the scope of the function
# they are effectively constructors
myClassConstructor = (arg1, arg2):
field1 = 4
field3 = arg1 + 3
add = (arg3):
return arg11 + arg2 + arg3
# instantiation
x = myClassConstructor(3, 2)
# fields and methods can be accessed using dot-syntax
print(x.field1)
print(x.add(7))
# null is synonymous with the empty tuple
null = ()
# algebraic data type could be either type (null is just a type, so a nullable MyClassConstructor is a null | MyClassConstructor)
y = if someLogic(): null
else: myClassConstructor(3, 2)
if y == null:
print(x)
else if y is myClassConstructor: # if y was created by this constructor function
print(y.add(3))
mySubClassConstructor = (arg1):
# current scope now contains the members of the myClassConstructor(arg1, 3) object
# treated as inheritance, implemented as composition
import * from myClassConstructor(arg1, 3)
# higher order constructor treated as an object
copyOfSubClassConstructor = mySubClassConstructor
z = copyOfMySubClassConstructor(3)
print(z.add(2))
# true because constructors are identical
assert(z is mySubClassConstructor)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment