A bit of library clean-up

This commit is contained in:
2026-05-19 20:04:01 -05:00
parent e2a1744508
commit 1c17d4c94a
4 changed files with 16 additions and 318 deletions

View File

@@ -10,39 +10,7 @@ bytesTail = matchList nothing (_ r : just r)
byteEq? = equal?
bytesLength = length
bytesAppend = append
bytesTake_ = y (self remaining n i :
matchList
t
(h r :
matchBool
t
(pair h (self r n (succ i)))
(equal? i n))
remaining)
bytesTake = n bytes : bytesTake_ bytes n 0
bytesDrop_ = y (self remaining n i :
matchList
t
(_ r :
matchBool
remaining
(self r n (succ i))
(equal? i n))
remaining)
bytesDrop = n bytes : bytesDrop_ bytes n 0
bytesSplitAt = n bytes : pair (bytesTake n bytes) (bytesDrop n bytes)
bytesEq? = y (self xs ys :
matchList
(matchList true (_ _ : false) ys)
(xh xt :
matchList
false
(yh yt : and? (byteEq? xh yh) (self xt yt))
ys)
xs)
bytesTake = take
bytesDrop = drop
bytesSplitAt = splitAt
bytesEq? = equal?

View File

@@ -91,8 +91,8 @@ onResult_ = action errCase okCase :
-- Convenience helpers
-- ---------------------------------------------------------------------------
print = s : bind (putStr s) (_ : pure t)
putStrLn = s : bind (putStr (append s "\n")) (_ : pure t)
print = s : void (putStr s)
putStrLn = s : void (putStr (append s "\n"))
-- ---------------------------------------------------------------------------
-- Result-aware file helpers
@@ -117,18 +117,12 @@ writeFileOrPrintError = (path contents okCase :
okCase)
copyFile = (src dst :
bind (readFile src)
(result :
matchResult
(err rest : putStrLn (append "Read failed: " err))
(contents rest :
bind (writeFile dst contents)
(wr :
matchResult
(err rest : putStrLn (append "Write failed: " err))
(ok rest : pure t)
wr))
result))
onResult (readFile src)
(err rest : putStrLn (append "Read failed: " err))
(contents rest :
onResult (writeFile dst contents)
(err rest : putStrLn (append "Write failed: " err))
(_ _ : pure t)))
-- ---------------------------------------------------------------------------
-- Resource-safe combinators

View File

@@ -157,8 +157,6 @@ partition_ = y (self pred xs trues falses :
partition = pred xs : partition_ pred xs t t
partition = pred xs : partition_ pred xs t t
strLength = length
strAppend = append
strEq? = equal?
@@ -191,11 +189,11 @@ contains? = y (self needle haystack :
lines_ = y (self str :
matchList
(acc current : append acc [(reverse current)])
(acc current : snoc (reverse current) acc)
(h r :
acc current :
matchBool
(self r (append acc [(reverse current)]) t)
(self r (snoc (reverse current) acc) t)
(self r acc (pair h current))
(equal? h 10))
str)
@@ -213,14 +211,14 @@ words_ = y (self str :
(acc current :
matchBool
acc
(append acc [(reverse current)])
(snoc (reverse current) acc)
(emptyList? current))
(h r :
acc current :
matchBool
(matchBool
(self r acc current)
(self r (append acc [(reverse current)]) t)
(self r (snoc (reverse current) acc) t)
(emptyList? current))
(self r acc (pair h current))
(equal? h 32))