Begin removing view related code and docs
This commit is contained in:
24
lib/guardedBase.tri
Normal file
24
lib/guardedBase.tri
Normal file
@@ -0,0 +1,24 @@
|
||||
!import "base" !Local
|
||||
!import "list" !Local
|
||||
!import "contracts" !Local
|
||||
!import "intensional" !Local
|
||||
|
||||
-- Runtime-guarded wrappers around partial or structurally-sensitive base/list
|
||||
-- functions. Each wrapper uses the frontend @ / =@ desugaring and is exported
|
||||
-- with an advertised contract so manifests carry the contract terms.
|
||||
|
||||
safeHead xs@(nonEmptyListOf anyC) =@anyC head xs
|
||||
safeTail xs@(nonEmptyListOf anyC) =@(listOf anyC) tail xs
|
||||
|
||||
safeDiv a@nat? b@(andC nat? nonZero?) =@nat? div a b
|
||||
|
||||
safeHalf n@(andC nat? evenC?) =@nat? div n 2
|
||||
|
||||
-- last is only guaranteed to return the maximum if the input list is sorted.
|
||||
sortedMax xs@(sortedList? nat?) =@nat? last xs
|
||||
|
||||
!export safeHead : fnContract (nonEmptyListOf anyC) anyC
|
||||
!export safeTail : fnContract (nonEmptyListOf anyC) (listOf anyC)
|
||||
!export safeDiv : fn2 nat? nonZero? nat?
|
||||
!export safeHalf : fnContract (andC nat? evenC?) nat?
|
||||
!export sortedMax : fnContract (sortedList? nat?) nat?
|
||||
Reference in New Issue
Block a user