!import "base.tri" !Local !import "list.tri" !Local nothing = t just = x : t x bytesNil? = emptyList? bytesHead = matchList nothing (h _ : just h) 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)