!import "prelude" !Local -- Custom contract combinators built directly on matchResult. myAndC = (c1 c2 value rest : matchResult (msg _ : contractErr msg rest) (v _ : c2 v rest) (c1 value rest)) -- Plain predicates lifted into contracts with a diagnostic message. natural? = guardC "natural" (n : gte? n 0) nonZero? = guardC "non-zero" (n : not? (isZero? n)) -- Phantom annotations let point-free definitions carry their own contracts. -- The base library now uses the same syntax, so head/tail/div etc. are -- guarded by default. myHead @(nonEmptyListOf anyC) =@anyC head myTail @(listOf anyC) =@(listOf anyC) tail myDiv @natural? @(myAndC natural? nonZero?) =@natural? div -- The `check` helper applies a contract to any value and returns the -- checked value (or the diagnostic message on failure). checkedSuccessor = check natural? (add 1 2) main = pair checkedSuccessor (myDiv 10 2)