Division and fixed pred
This commit is contained in:
35
lib/base.tri
35
lib/base.tri
@@ -178,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)
|
||||
|
||||
@@ -231,6 +228,24 @@ 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)))
|
||||
|
||||
-- ---------------------------------------------------------------------------
|
||||
-- Result combinators
|
||||
-- ---------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user