Skip to content

Instantly share code, notes, and snippets.

@mlippens
Last active December 28, 2015 03:49
Show Gist options
  • Save mlippens/7437702 to your computer and use it in GitHub Desktop.
Save mlippens/7437702 to your computer and use it in GitHub Desktop.
# bar.coffee
root = exports ? this
C = root['contracts-js']
{id,hi} = C.use root['foo'], "bar"
console.log id 3#ok
console.log hi 2
#Uncaught Error: Contract violation: expected <Num>, actual: "hello"
#Value guarded in: bar -- blame is on: foo
#Parent contracts:
#(Num) -> Num
# foo.coffee
root = exports ? this
C = root['contracts-js']
exports = C.exports "foo"
exports.id = C.guard(C.fun(C.Num,C.Num),(x)->x)
exports.hi = C.guard(C.fun(C.Num,C.Num),(x)-> "hello")
root['foo'] = exports
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script src="libs/contracts.js"></script>
<script src="foo.js"></script>
<script src="bar.js"></script>
</head>
<body>
<p> Look at the console yo!</p>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment