Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

How about an example that is actually readable and easy to follow?


Here, I will write one by hand right now:

  d IntegerMath : SomeInterface, SomeOtherInterface

    someProperty:I
    someOtherProperty:I-M

    referenceProperty:IntegerMath+R+N // nullable
    recursiveProperty:IntegerMath+N // error! needs +R

    f stuff(myObj: IntegerMath+M+R, newValue: I+M)
      newValue = 4 // modifies caller's reference
      myObj.someProperty = newValue // error, need newValue.c()
      myObj.someOtherProperty = 4 // error, immutable property

  IntegerMath.max = f(first:I, second:I):I
    r => first > second ? first : second

  IntegerMath.min = f(first:I, second:I):I => first < second ? first : second
    
  // let's use the class
  im = IntegerMath.n({someOtherProperty: 4}) // infers im:IntegerMath
  im.someProperty = 3
  im.stuff(im, someInteger) // modifies both
  result = Math.sort([1,2,3], IntegerMath.max) // infers result:[I]
  another = Math.sort(result, f(first:I, second:I):I => first > second ? first : second)

  // conditional code
  [1,2,3].x( f(k)
    k > 2
      ? console.log(k)
      : (
        result = k
        console.log(k-2)
      )
    // this is a closure but doesn't assign
    // anything to +R variables, so it's not +R itself
    // in Swift language, it's not "escaping"




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: