Created
          February 23, 2015 12:00 
        
      - 
      
- 
        Save josejuan/7b56c901c38e2d1da899 to your computer and use it in GitHub Desktop. 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | // Let `Int` instancing `Eq`, `Ord` and `Show` classes, then: | |
| var n = function (x) { return Int.make(x) }; // alias | |
| // testing Int type | |
| console.log( n(4).equalTo(n(5)) ); // false | |
| console.log( n(3).equalTo(n(3)) ); // true | |
| console.log( n(4).compareTo(n(5)) ); // -1 | |
| console.log( n(5).compareTo(n(3)) ); // 2 | |
| console.log( n(2).compareTo(n(2)) ); // 0 | |
| console.log( n(1234).show() ); // "1234" | |
| // Int tuple with all auto-derived!!!! | |
| var TupleInt = Instance("TupleIntEq" , Eq, | |
| Instance("TupleIntOrd" , Ord, | |
| Instance("TupleIntShow", Show, Type("TupleInt_", [Int, Int]), {}), {}), {}); | |
| // aliases | |
| var tup = function (a, b) { return TupleInt.make(a, b) }; | |
| var itup = function (a, b) { return TupleInt.make([Int.make(a), Int.make(b)]) }; | |
| var ta = itup(3, 5); | |
| var tb = itup(2, 7); | |
| console.log( ta.equalTo(tb) ); // false | |
| console.log( tb.equalTo(tb) ); // true | |
| console.log( ta.compareTo(tb) ); // 1 | |
| console.log( tb.compareTo(ta) ); // -1 | |
| console.log( ta.compareTo(ta) ); // 0 | |
| console.log( ta.show() ); // "3; 5" | |
| console.log( tb.show() ); // "2; 7" | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment