442 lines
11 KiB
Plaintext
442 lines
11 KiB
Plaintext
!import "base" !Local
|
|
|
|
_ = t
|
|
|
|
matchList = a b : triage a _ b
|
|
|
|
emptyList? = matchList true (_ _ : false)
|
|
head = matchList t (head _ : head)
|
|
tail = matchList t (_ tail : tail)
|
|
|
|
append_ self xs ys =
|
|
matchList
|
|
ys
|
|
(h r : pair h (self r ys))
|
|
xs
|
|
append = xs ys : y append_ xs ys
|
|
|
|
lExist?_ self x xs =
|
|
matchList
|
|
false
|
|
(h r : or? (equal? x h) (self x r))
|
|
xs
|
|
lExist? = x xs : y lExist?_ x xs
|
|
|
|
map_ self l f =
|
|
matchList
|
|
t
|
|
(h r : pair (f h) (self r f))
|
|
l
|
|
map = f l : y map_ l f
|
|
|
|
filter_ self l f =
|
|
matchList
|
|
t
|
|
(h r :
|
|
matchBool
|
|
(pair h (self r f))
|
|
(self r f)
|
|
(f h))
|
|
l
|
|
filter = f l : y filter_ l f
|
|
|
|
foldl_ self l f acc =
|
|
matchList
|
|
acc
|
|
(h r : self r f (f acc h))
|
|
l
|
|
foldl = f x l : y foldl_ l f x
|
|
|
|
foldr_ self l f x =
|
|
matchList
|
|
x
|
|
(h r : f (self r f x) h)
|
|
l
|
|
foldr = f x l : y foldr_ l f x
|
|
|
|
length_ self xs =
|
|
matchList
|
|
0
|
|
(_ r : succ (self r))
|
|
xs
|
|
length = xs : y length_ xs
|
|
|
|
reverse_ self xs acc =
|
|
matchList
|
|
acc
|
|
(h r : self r (pair h acc))
|
|
xs
|
|
reverse = xs : y reverse_ xs t
|
|
|
|
snoc_ self x xs =
|
|
matchList
|
|
(pair x t)
|
|
(h r : pair h (self x r))
|
|
xs
|
|
snoc = x xs : y snoc_ x xs
|
|
|
|
count_ self x xs =
|
|
matchList
|
|
0
|
|
(h r :
|
|
matchBool
|
|
(succ (self x r))
|
|
(self x r)
|
|
(equal? x h))
|
|
xs
|
|
count = x xs : y count_ x xs
|
|
|
|
last_ self xs =
|
|
matchList
|
|
t
|
|
(h r :
|
|
matchBool
|
|
h
|
|
(self r)
|
|
(emptyList? r))
|
|
xs
|
|
last = xs : y last_ xs
|
|
|
|
all?_ self pred xs =
|
|
matchList
|
|
true
|
|
(h r : and? (pred h) (self pred r))
|
|
xs
|
|
all? = pred xs : y all?_ pred xs
|
|
|
|
any?_ self pred xs =
|
|
matchList
|
|
false
|
|
(h r : or? (pred h) (self pred r))
|
|
xs
|
|
any? = pred xs : y any?_ pred xs
|
|
|
|
intersect = xs ys : filter (x : lExist? x ys) xs
|
|
|
|
nth_ self xs n i =
|
|
matchList
|
|
t
|
|
(h r :
|
|
matchBool
|
|
h
|
|
(self r n (succ i))
|
|
(equal? i n))
|
|
xs
|
|
nth = n xs : y nth_ xs n 0
|
|
|
|
headMaybe = matchList nothing (h _ : just h)
|
|
|
|
lastMaybe_ self xs =
|
|
matchList
|
|
nothing
|
|
(h r :
|
|
matchBool
|
|
(just h)
|
|
(self r)
|
|
(emptyList? r))
|
|
xs
|
|
lastMaybe = xs : y lastMaybe_ xs
|
|
|
|
nthMaybe_ self xs n i =
|
|
matchList
|
|
nothing
|
|
(h r :
|
|
matchBool
|
|
(just h)
|
|
(self r n (succ i))
|
|
(equal? i n))
|
|
xs
|
|
nthMaybe = n xs : y nthMaybe_ xs n 0
|
|
|
|
take_ self xs n i =
|
|
matchList
|
|
t
|
|
(h r :
|
|
matchBool
|
|
t
|
|
(pair h (self r n (succ i)))
|
|
(equal? i n))
|
|
xs
|
|
take = n xs : y take_ xs n 0
|
|
|
|
drop_ self xs n i =
|
|
matchBool
|
|
xs
|
|
(matchList
|
|
t
|
|
(_ r : self r n (succ i))
|
|
xs)
|
|
(equal? i n)
|
|
drop = n xs : y drop_ xs n 0
|
|
|
|
splitAt = n xs : pair (take n xs) (drop n xs)
|
|
|
|
concatMap_ self f xs =
|
|
matchList
|
|
t
|
|
(h r : append (f h) (self f r))
|
|
xs
|
|
concatMap = f xs : y concatMap_ f xs
|
|
|
|
find_ self pred xs =
|
|
matchList
|
|
nothing
|
|
(h r :
|
|
matchBool
|
|
(just h)
|
|
(self pred r)
|
|
(pred h))
|
|
xs
|
|
find = pred xs : y find_ pred xs
|
|
|
|
partition_ self pred xs trues falses =
|
|
matchList
|
|
(pair (reverse trues) (reverse falses))
|
|
(h r :
|
|
matchBool
|
|
(self pred r (pair h trues) falses)
|
|
(self pred r trues (pair h falses))
|
|
(pred h))
|
|
xs
|
|
partition = pred xs : y partition_ pred xs t t
|
|
|
|
strLength = length
|
|
strAppend = append
|
|
strEq? = equal?
|
|
strEmpty? = emptyList?
|
|
|
|
startsWith?_ self prefix input =
|
|
matchList
|
|
true
|
|
(ph pr :
|
|
matchList
|
|
false
|
|
(sh sr :
|
|
matchBool
|
|
(self pr sr)
|
|
false
|
|
(equal? ph sh))
|
|
input)
|
|
prefix
|
|
startsWith? = prefix input : y startsWith?_ prefix input
|
|
|
|
endsWith? = prefix str : startsWith? (reverse prefix) (reverse str)
|
|
|
|
contains?_ self needle haystack =
|
|
matchBool
|
|
true
|
|
(matchList
|
|
false
|
|
(_ r : self needle r)
|
|
haystack)
|
|
(startsWith? needle haystack)
|
|
contains? = needle haystack : y contains?_ needle haystack
|
|
|
|
linesFinish current accRev =
|
|
reverse (pair (reverse current) accRev)
|
|
|
|
lines_ self str accRev current =
|
|
matchList
|
|
(linesFinish current accRev)
|
|
(h r :
|
|
matchBool
|
|
(self r (pair (reverse current) accRev) t)
|
|
(self r accRev (pair h current))
|
|
(equal? h 10))
|
|
str
|
|
lines = str : y lines_ str t t
|
|
|
|
unlines_ self lines =
|
|
matchList
|
|
""
|
|
(h r : append h (append "\n" (self r)))
|
|
lines
|
|
unlines = lines : y unlines_ lines
|
|
|
|
wordsAdd current accRev =
|
|
matchBool
|
|
accRev
|
|
(pair (reverse current) accRev)
|
|
(emptyList? current)
|
|
|
|
words_ self str accRev current =
|
|
matchList
|
|
(reverse (wordsAdd current accRev))
|
|
(h r :
|
|
matchBool
|
|
(self r (wordsAdd current accRev) t)
|
|
(self r accRev (pair h current))
|
|
(equal? h 32))
|
|
str
|
|
words = str : y words_ str t t
|
|
|
|
unwords_ self words =
|
|
matchList
|
|
""
|
|
(h r :
|
|
matchBool
|
|
h
|
|
(append h (append " " (self r)))
|
|
(emptyList? r))
|
|
words
|
|
unwords = words : y unwords_ words
|
|
|
|
zipWith_ self f xs ys =
|
|
matchList
|
|
t
|
|
(xh xt :
|
|
matchList
|
|
t
|
|
(yh yt : pair (f xh yh) (self f xt yt))
|
|
ys)
|
|
xs
|
|
zipWith = f xs ys : y zipWith_ f xs ys
|
|
|
|
-- ---------------------------------------------------------------------------
|
|
-- View facts
|
|
--
|
|
-- Value-level metadata consumed by View tooling. These facts are ordinary Tree
|
|
-- Calculus data, not host-side assumptions and not part of the public stdlib
|
|
-- API exported by module manifests.
|
|
-- ---------------------------------------------------------------------------
|
|
|
|
viewFacts =
|
|
[(factsFact "matchList" factsTrusted
|
|
(factsForall [0 1]
|
|
(factsFn
|
|
[(factsVar 1)
|
|
(factsFn
|
|
[(factsVar 0) (factsList (factsVar 0))]
|
|
(factsVar 1))
|
|
(factsList (factsVar 0))]
|
|
(factsVar 1))))
|
|
(factsFact "emptyList?" factsTrusted
|
|
(factsForall [0]
|
|
(factsFn [(factsList (factsVar 0))] factsBool)))
|
|
(factsFact "tail" factsTrusted
|
|
(factsForall [0]
|
|
(factsFn [(factsList (factsVar 0))] (factsList (factsVar 0)))))
|
|
(factsFact "append" factsTrusted
|
|
(factsForall [0]
|
|
(factsFn
|
|
[(factsList (factsVar 0))
|
|
(factsList (factsVar 0))]
|
|
(factsList (factsVar 0)))))
|
|
(factsFact "lExist?" factsTrusted
|
|
(factsForall [0]
|
|
(factsFn [(factsVar 0) (factsList (factsVar 0))] factsBool)))
|
|
(factsFact "map" factsTrusted
|
|
(factsForall [0 1]
|
|
(factsFn
|
|
[(factsFn [(factsVar 0)] (factsVar 1))
|
|
(factsList (factsVar 0))]
|
|
(factsList (factsVar 1)))))
|
|
(factsFact "filter" factsTrusted
|
|
(factsForall [0]
|
|
(factsFn
|
|
[(factsFn [(factsVar 0)] factsBool)
|
|
(factsList (factsVar 0))]
|
|
(factsList (factsVar 0)))))
|
|
(factsFact "foldl" factsTrusted
|
|
(factsForall [0 1]
|
|
(factsFn
|
|
[(factsFn [(factsVar 1) (factsVar 0)] (factsVar 1))
|
|
(factsVar 1)
|
|
(factsList (factsVar 0))]
|
|
(factsVar 1))))
|
|
(factsFact "foldr" factsTrusted
|
|
(factsForall [0 1]
|
|
(factsFn
|
|
[(factsFn [(factsVar 1) (factsVar 0)] (factsVar 1))
|
|
(factsVar 1)
|
|
(factsList (factsVar 0))]
|
|
(factsVar 1))))
|
|
(factsFact "length" factsTrusted
|
|
(factsForall [0]
|
|
(factsFn [(factsList (factsVar 0))] factsByte)))
|
|
(factsFact "reverse" factsTrusted
|
|
(factsForall [0]
|
|
(factsFn [(factsList (factsVar 0))] (factsList (factsVar 0)))))
|
|
(factsFact "snoc" factsTrusted
|
|
(factsForall [0]
|
|
(factsFn [(factsVar 0) (factsList (factsVar 0))] (factsList (factsVar 0)))))
|
|
(factsFact "count" factsTrusted
|
|
(factsForall [0]
|
|
(factsFn [(factsVar 0) (factsList (factsVar 0))] factsByte)))
|
|
(factsFact "all?" factsTrusted
|
|
(factsForall [0]
|
|
(factsFn [(factsFn [(factsVar 0)] factsBool) (factsList (factsVar 0))] factsBool)))
|
|
(factsFact "any?" factsTrusted
|
|
(factsForall [0]
|
|
(factsFn [(factsFn [(factsVar 0)] factsBool) (factsList (factsVar 0))] factsBool)))
|
|
(factsFact "intersect" factsTrusted
|
|
(factsForall [0]
|
|
(factsFn [(factsList (factsVar 0)) (factsList (factsVar 0))] (factsList (factsVar 0)))))
|
|
(factsFact "headMaybe" factsTrusted
|
|
(factsForall [0]
|
|
(factsFn [(factsList (factsVar 0))] (factsMaybe (factsVar 0)))))
|
|
(factsFact "lastMaybe" factsTrusted
|
|
(factsForall [0]
|
|
(factsFn [(factsList (factsVar 0))] (factsMaybe (factsVar 0)))))
|
|
(factsFact "nthMaybe" factsTrusted
|
|
(factsForall [0]
|
|
(factsFn [factsByte (factsList (factsVar 0))] (factsMaybe (factsVar 0)))))
|
|
(factsFact "take" factsTrusted
|
|
(factsForall [0]
|
|
(factsFn [factsByte (factsList (factsVar 0))] (factsList (factsVar 0)))))
|
|
(factsFact "drop" factsTrusted
|
|
(factsForall [0]
|
|
(factsFn [factsByte (factsList (factsVar 0))] (factsList (factsVar 0)))))
|
|
(factsFact "splitAt" factsTrusted
|
|
(factsForall [0]
|
|
(factsFn
|
|
[factsByte (factsList (factsVar 0))]
|
|
(factsPair (factsList (factsVar 0)) (factsList (factsVar 0))))))
|
|
(factsFact "concatMap" factsTrusted
|
|
(factsForall [0 1]
|
|
(factsFn
|
|
[(factsFn [(factsVar 0)] (factsList (factsVar 1)))
|
|
(factsList (factsVar 0))]
|
|
(factsList (factsVar 1)))))
|
|
(factsFact "find" factsTrusted
|
|
(factsForall [0]
|
|
(factsFn
|
|
[(factsFn [(factsVar 0)] factsBool)
|
|
(factsList (factsVar 0))]
|
|
(factsMaybe (factsVar 0)))))
|
|
(factsFact "partition" factsTrusted
|
|
(factsForall [0]
|
|
(factsFn
|
|
[(factsFn [(factsVar 0)] factsBool)
|
|
(factsList (factsVar 0))]
|
|
(factsPair (factsList (factsVar 0)) (factsList (factsVar 0))))))
|
|
(factsFact "strLength" factsTrusted
|
|
(factsFn [factsString] factsByte))
|
|
(factsFact "strAppend" factsTrusted
|
|
(factsFn [factsString factsString] factsString))
|
|
(factsFact "strEq?" factsTrusted
|
|
(factsFn [factsString factsString] factsBool))
|
|
(factsFact "strEmpty?" factsTrusted
|
|
(factsFn [factsString] factsBool))
|
|
(factsFact "startsWith?" factsTrusted
|
|
(factsFn [factsString factsString] factsBool))
|
|
(factsFact "endsWith?" factsTrusted
|
|
(factsFn [factsString factsString] factsBool))
|
|
(factsFact "contains?" factsTrusted
|
|
(factsFn [factsString factsString] factsBool))
|
|
(factsFact "lines" factsTrusted
|
|
(factsFn [factsString] (factsList factsString)))
|
|
(factsFact "unlines" factsTrusted
|
|
(factsFn [(factsList factsString)] factsString))
|
|
(factsFact "words" factsTrusted
|
|
(factsFn [factsString] (factsList factsString)))
|
|
(factsFact "unwords" factsTrusted
|
|
(factsFn [(factsList factsString)] factsString))
|
|
(factsFact "zipWith" factsTrusted
|
|
(factsForall [0 1 2]
|
|
(factsFn
|
|
[(factsFn [(factsVar 0) (factsVar 1)] (factsVar 2))
|
|
(factsList (factsVar 0))
|
|
(factsList (factsVar 1))]
|
|
(factsList (factsVar 2)))))]
|