Equivalence principle

This isn’t rocket science, it’s YAFL. In YAFL these two statements are considered to be equivalent:

  • let square = (x) => x * x
  • fun square(x) => x * x

If you look deep inside the AST you’ll see that there is a separate mechanism for representing let and fun objects, but that is really there to make debugging the compiler easier. Semantically, in the YAFL language, they are the same.

YAFL also supports overloading.

Think about it…. The above two statements are equivalent, and overloading is supported. Sooooo

  • let square = (x: Float32) => x * x
  • let square = (x: Float64) => x * x

it is completely valid to have two lets of the same name, and the compiler will deal with it gracefully. We do this by distinguishing loads by the receiver type, i.e. what the recipient of an expression expects can be a factor in finding which ‘square’ to load.

This goes one step further, as it’s not just to do with lambdas and functions. The following is also valid:

  • let anumber = 100i32
  • let anumber = 100i64
  • fun square(x: Int32) => x * x
  • fun main() => square(anumber)

Because of the context in which ‘anumber’ is used, it is clear that we are referring to the first instance. Just like a function call context with parameters can make it clear which lambda type we are looking for when loading ‘square’.

There is symmetry here that works, it just works. But it does start to mess with my mind when generics comes into the picture, and that comes next.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s