Begin removing view related code and docs
This commit is contained in:
98
lib/base.tri
98
lib/base.tri
@@ -119,6 +119,47 @@ maybeBind m f = matchMaybe nothing f m
|
||||
maybeOr default m = matchMaybe default id m
|
||||
maybe? = matchMaybe false (_ : true)
|
||||
|
||||
-- ---------------------------------------------------------------------------
|
||||
-- Lazy eliminators
|
||||
--
|
||||
-- A strict eliminator evaluates both branches because they are ordinary
|
||||
-- arguments. Give a branch that recurses, looks something up, or builds
|
||||
-- structure to one of these instead: it becomes a thunk and only the selected
|
||||
-- branch is ever applied.
|
||||
-- ---------------------------------------------------------------------------
|
||||
|
||||
lazyBool = (thenK elseK cond :
|
||||
((chosen : chosen t)
|
||||
(matchBool
|
||||
thenK
|
||||
elseK
|
||||
cond)))
|
||||
|
||||
-- This module has no list matcher, so `triage` is used directly: a cons is a
|
||||
-- Fork, which is why the cons case sits in the fork slot, exactly as in
|
||||
-- `matchList` in lib/list.tri.
|
||||
lazyList = (nilK consK xs :
|
||||
((chosen : chosen t)
|
||||
(triage
|
||||
nilK
|
||||
_
|
||||
(h r : (_ : consK h r))
|
||||
xs)))
|
||||
|
||||
lazyMaybe = (noneK someK m :
|
||||
((chosen : chosen t)
|
||||
(matchMaybe
|
||||
noneK
|
||||
(x : (_ : someK x))
|
||||
m)))
|
||||
|
||||
lazyResult = (errK okK result :
|
||||
((chosen : chosen t)
|
||||
(matchResult
|
||||
(code rest : (_ : errK code rest))
|
||||
(value rest : (_ : okK value rest))
|
||||
result)))
|
||||
|
||||
-- ---------------------------------------------------------------------------
|
||||
-- Basic arithmetic
|
||||
-- ---------------------------------------------------------------------------
|
||||
@@ -137,18 +178,15 @@ andLazy? = (a bK :
|
||||
|
||||
pred = y (self : triage
|
||||
0
|
||||
(_ : 0)
|
||||
0
|
||||
(bit rest :
|
||||
matchBool
|
||||
(matchBool
|
||||
ifLazy
|
||||
bit
|
||||
(_ : matchBool
|
||||
(t t rest)
|
||||
0
|
||||
(pair 0 rest)
|
||||
(equal? rest 0))
|
||||
(matchBool
|
||||
0
|
||||
(pair 1 (self rest))
|
||||
(equal? rest 0))
|
||||
bit))
|
||||
rest)
|
||||
(_ : t (t t) (self rest))))
|
||||
|
||||
isZero? = triage true (_ : false) (_ _ : false)
|
||||
|
||||
@@ -190,6 +228,42 @@ mul = y (self a b :
|
||||
(_ : 0)
|
||||
(_ : add a (self a (pred b))))
|
||||
|
||||
div = y (self a b :
|
||||
ifLazy
|
||||
(isZero? b)
|
||||
(_ : 0)
|
||||
(_ : ifLazy
|
||||
(lt? a b)
|
||||
(_ : 0)
|
||||
(_ : succ (self (sub a b) b))))
|
||||
|
||||
mod = y (self a b :
|
||||
ifLazy
|
||||
(isZero? b)
|
||||
(_ : 0)
|
||||
(_ : ifLazy
|
||||
(lt? a b)
|
||||
(_ : a)
|
||||
(_ : self (sub a b) b)))
|
||||
|
||||
pow = y (self a b :
|
||||
ifLazy
|
||||
(isZero? b)
|
||||
(_ : 1)
|
||||
(_ : mul a (self a (pred b))))
|
||||
|
||||
even? n = (triage
|
||||
true
|
||||
(_ : false)
|
||||
(bit _ : isZero? bit)
|
||||
n)
|
||||
|
||||
odd? = (n : not? (even? n))
|
||||
|
||||
min = (a b : ifLazy (lte? a b) (_ : a) (_ : b))
|
||||
|
||||
max = (a b : ifLazy (lte? a b) (_ : b) (_ : a))
|
||||
|
||||
-- ---------------------------------------------------------------------------
|
||||
-- Result combinators
|
||||
-- ---------------------------------------------------------------------------
|
||||
@@ -217,7 +291,3 @@ resultMapErr = (f result :
|
||||
(code rest : err (f code) rest)
|
||||
(value rest : ok value rest)
|
||||
result)
|
||||
|
||||
-- ---------------------------------------------------------------------------
|
||||
-- View facts
|
||||
-- ---------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user