Browse files

minor edits

  • Loading branch information...
1 parent 6b2c2bb commit eda5cb64c26211e19a705fa2dabe75b1df33cdbd Arjun Guha committed Oct 31, 2009
Showing with 14 additions and 5 deletions.
  1. +14 −5 data/contracts.js
View
19 data/contracts.js
@@ -1,3 +1,8 @@
+// The type of a contract combinator is: name -> args ... -> contract
+//
+// name is a human-readable name for the contract. args .. are constructor-
+// specified arguments and contract is the resulting contract.
+
var contracts = { };
contracts.map = function(f,arr) {
@@ -8,6 +13,7 @@ contracts.map = function(f,arr) {
return dest;
};
+
contracts.zipWith = function(f,arr1,arr2) {
var dest = [ ];
var len = Math.min(arr1.length, arr2.length);
@@ -17,6 +23,7 @@ contracts.zipWith = function(f,arr1,arr2) {
return dest;
};
+
contracts.blame = function(guilty,expected,received,message,loc) {
var guiltyMsg = typeof(guilty) == "string"
? guilty : guilty.value;
@@ -32,12 +39,7 @@ contracts.blame = function(guilty,expected,received,message,loc) {
throw err;
}
-// The type of a contract combinator is: name -> args ... -> contract
-//
-// name is a human-readable name for the contract. args .. are constructor-
-// specified arguments and contract is the resulting contract.
-
contracts.flat = function(name) {
return function(pred) {
return {
@@ -94,6 +96,7 @@ contracts.unsizedArray = function(name) {
};
};
+
contracts.fixedArray = function(name) {
return function() {
var elts = arguments;
@@ -139,10 +142,12 @@ contracts.fixedArray = function(name) {
};
};
+
contracts.isUndefined = contracts.flat(function(val) {
return val === undefined;
});
+
contracts.varArityFunc = function(name) {
return function(fixedArgs,restArgs,result) {
return {
@@ -186,6 +191,7 @@ contracts.varArityFunc = function(name) {
};
};
+
// Ensures value is an instanceof constr before checking that its shape
// matches sig. constrId is a human-readable name for the constructor.
contracts.instance = function(name) {
@@ -217,6 +223,7 @@ contracts.instance = function(name) {
};
};
+
contracts.obj = function(name) {
return function(sig) {
return {
@@ -254,6 +261,7 @@ contracts.obj = function(name) {
};
};
+
// pos is the name of val. neg should be the name of the calling context.
// Since we do not rewrite call-sites, neg is simply "client".
// However, if ctc.isHigherOrder, we can determine the name of the calling
@@ -279,6 +287,7 @@ contracts.guard = function(ctc,val,pos,neg,loc) {
}
};
+
// Derived from http://eriwen.com/javascript/js-stack-trace/
contracts.stackTrace = function() {
var callstack = [];

0 comments on commit eda5cb6

Please sign in to comment.