Useful but limited polymorphism
This commit is contained in:
178
lib/base.tri
178
lib/base.tri
@@ -1,8 +1,8 @@
|
||||
false = t
|
||||
_ = t
|
||||
true = t t
|
||||
id a = a
|
||||
const a b = a
|
||||
id a@_a =@_a a
|
||||
const a@_a b@_b =@_a a
|
||||
pair = t
|
||||
if cond then else = t (t else (t t then)) t cond
|
||||
|
||||
@@ -10,7 +10,7 @@ y = ((mut wait fun : wait mut (x : fun (wait mut x)))
|
||||
(x : x x)
|
||||
(a0 a1 a2 : t (t a0) (t t a2) a1))
|
||||
|
||||
compose f g x = f (g x)
|
||||
compose f@(Fn [_b] _c) g@(Fn [_a] _b) x@_a =@_c f (g x)
|
||||
|
||||
triage leaf stem fork = t (t leaf stem) fork
|
||||
test = triage "Leaf" (_ : "Stem") (_ _ : "Fork")
|
||||
@@ -114,9 +114,9 @@ matchMaybe nothingCase justCase maybe =
|
||||
maybe
|
||||
|
||||
maybe default f m = matchMaybe default f m
|
||||
maybeMap f m = matchMaybe nothing (x : just (f x)) m
|
||||
maybeBind m f = matchMaybe nothing f m
|
||||
maybeOr default m = matchMaybe default id m
|
||||
maybeMap f@(Fn [_a] _b) m@(Maybe _a) =@(Maybe _b) matchMaybe nothing (compose just f) m
|
||||
maybeBind m@(Maybe _a) f@(Fn [_a] (Maybe _b)) =@(Maybe _b) matchMaybe nothing f m
|
||||
maybeOr default@_a m@(Maybe _a) =@_a matchMaybe default id m
|
||||
maybe? = matchMaybe false (_ : true)
|
||||
|
||||
-- ---------------------------------------------------------------------------
|
||||
@@ -217,3 +217,169 @@ resultMapErr = (f result :
|
||||
(code rest : err (f code) rest)
|
||||
(value rest : ok value rest)
|
||||
result)
|
||||
|
||||
-- ---------------------------------------------------------------------------
|
||||
-- View facts
|
||||
-- ---------------------------------------------------------------------------
|
||||
|
||||
factsFact name provenance view = pair name (pair provenance view)
|
||||
factsChecked = 0
|
||||
factsTrusted = 1
|
||||
factsUnchecked = 2
|
||||
factsField tag value = pair tag value
|
||||
factsRecord tag fields = pair tag fields
|
||||
factsVar id = factsRecord 8 [(factsField 10 id)]
|
||||
factsForall binders body =
|
||||
factsRecord 9 [(factsField 11 binders) (factsField 12 body)]
|
||||
factsFn args result =
|
||||
factsRecord 1 [(factsField 0 args) (factsField 1 result)]
|
||||
factsAny = factsRecord 0 []
|
||||
factsRef symbol = factsRecord 2 [(factsField 2 symbol)]
|
||||
factsBool = factsRef 0
|
||||
factsString = factsRef 1
|
||||
factsByte = factsRef 2
|
||||
factsUnit = factsRef 3
|
||||
factsMaybe elem = factsRecord 4 [(factsField 3 elem)]
|
||||
factsList elem = factsRecord 3 [(factsField 3 elem)]
|
||||
factsPair left right = factsRecord 5 [(factsField 4 left) (factsField 5 right)]
|
||||
factsResult err ok = factsRecord 6 [(factsField 6 err) (factsField 7 ok)]
|
||||
|
||||
viewFacts =
|
||||
[ (factsFact "pair" factsTrusted
|
||||
(factsForall [0]
|
||||
(factsFn
|
||||
[(factsVar 0) (factsList (factsVar 0))]
|
||||
(factsList (factsVar 0)))))
|
||||
(factsFact "nothing" factsTrusted
|
||||
(factsForall [0]
|
||||
(factsMaybe (factsVar 0))))
|
||||
(factsFact "just" factsTrusted
|
||||
(factsForall [0]
|
||||
(factsFn [(factsVar 0)] (factsMaybe (factsVar 0)))))
|
||||
(factsFact "false" factsTrusted factsBool)
|
||||
(factsFact "true" factsTrusted factsBool)
|
||||
(factsFact "if" factsTrusted
|
||||
(factsForall [0]
|
||||
(factsFn [factsBool (factsVar 0) (factsVar 0)] (factsVar 0))))
|
||||
(factsFact "triage" factsTrusted
|
||||
(factsForall [0]
|
||||
(factsFn [factsAny factsAny factsAny factsAny] (factsVar 0))))
|
||||
(factsFact "test" factsTrusted factsString)
|
||||
(factsFact "matchBool" factsTrusted
|
||||
(factsForall [0]
|
||||
(factsFn
|
||||
[(factsVar 0) (factsVar 0) factsBool]
|
||||
(factsVar 0))))
|
||||
(factsFact "lAnd" factsTrusted
|
||||
(factsFn [factsBool factsBool] factsBool))
|
||||
(factsFact "lOr" factsTrusted
|
||||
(factsFn [factsBool factsBool] factsBool))
|
||||
(factsFact "matchPair" factsTrusted
|
||||
(factsForall [0 1 2]
|
||||
(factsFn
|
||||
[(factsFn [(factsVar 0) (factsVar 1)] (factsVar 2))
|
||||
(factsPair (factsVar 0) (factsVar 1))]
|
||||
(factsVar 2))))
|
||||
(factsFact "fst" factsTrusted
|
||||
(factsForall [0 1]
|
||||
(factsFn [(factsPair (factsVar 0) (factsVar 1))] (factsVar 0))))
|
||||
(factsFact "snd" factsTrusted
|
||||
(factsForall [0 1]
|
||||
(factsFn [(factsPair (factsVar 0) (factsVar 1))] (factsVar 1))))
|
||||
(factsFact "not?" factsTrusted
|
||||
(factsFn [factsBool] factsBool))
|
||||
(factsFact "and?" factsTrusted
|
||||
(factsFn [factsBool factsBool] factsBool))
|
||||
(factsFact "or?" factsTrusted
|
||||
(factsFn [factsBool factsBool] factsBool))
|
||||
(factsFact "xor?" factsTrusted
|
||||
(factsFn [factsBool factsBool] factsBool))
|
||||
(factsFact "equal?" factsTrusted
|
||||
(factsForall [0]
|
||||
(factsFn [(factsVar 0) (factsVar 0)] factsBool)))
|
||||
(factsFact "succ" factsTrusted
|
||||
(factsFn [factsByte] factsByte))
|
||||
(factsFact "pred" factsTrusted
|
||||
(factsFn [factsByte] factsByte))
|
||||
(factsFact "isZero?" factsTrusted
|
||||
(factsFn [factsByte] factsBool))
|
||||
(factsFact "add" factsTrusted
|
||||
(factsFn [factsByte factsByte] factsByte))
|
||||
(factsFact "sub" factsTrusted
|
||||
(factsFn [factsByte factsByte] factsByte))
|
||||
(factsFact "lte?" factsTrusted
|
||||
(factsFn [factsByte factsByte] factsBool))
|
||||
(factsFact "gte?" factsTrusted
|
||||
(factsFn [factsByte factsByte] factsBool))
|
||||
(factsFact "lt?" factsTrusted
|
||||
(factsFn [factsByte factsByte] factsBool))
|
||||
(factsFact "gt?" factsTrusted
|
||||
(factsFn [factsByte factsByte] factsBool))
|
||||
(factsFact "mul" factsTrusted
|
||||
(factsFn [factsByte factsByte] factsByte))
|
||||
(factsFact "matchMaybe" factsTrusted
|
||||
(factsForall [0 1]
|
||||
(factsFn
|
||||
[(factsVar 1)
|
||||
(factsFn [(factsVar 0)] (factsVar 1))
|
||||
(factsMaybe (factsVar 0))]
|
||||
(factsVar 1))))
|
||||
(factsFact "maybe" factsTrusted
|
||||
(factsForall [0 1]
|
||||
(factsFn
|
||||
[(factsVar 1)
|
||||
(factsFn [(factsVar 0)] (factsVar 1))
|
||||
(factsMaybe (factsVar 0))]
|
||||
(factsVar 1))))
|
||||
(factsFact "maybe?" factsTrusted
|
||||
(factsForall [0]
|
||||
(factsFn [(factsMaybe (factsVar 0))] factsBool)))
|
||||
(factsFact "ifLazy" factsTrusted
|
||||
(factsForall [0]
|
||||
(factsFn
|
||||
[factsBool
|
||||
(factsFn [factsUnit] (factsVar 0))
|
||||
(factsFn [factsUnit] (factsVar 0))]
|
||||
(factsVar 0))))
|
||||
(factsFact "andLazy?" factsTrusted
|
||||
(factsFn [factsBool (factsFn [factsUnit] factsBool)] factsBool))
|
||||
(factsFact "ok" factsTrusted
|
||||
(factsForall [0 1]
|
||||
(factsFn [(factsVar 1) factsAny] (factsResult (factsVar 0) (factsVar 1)))))
|
||||
(factsFact "err" factsTrusted
|
||||
(factsForall [0 1]
|
||||
(factsFn [(factsVar 0) factsAny] (factsResult (factsVar 0) (factsVar 1)))))
|
||||
(factsFact "matchResult" factsTrusted
|
||||
(factsForall [0 1 2]
|
||||
(factsFn
|
||||
[(factsFn [(factsVar 0) factsAny] (factsVar 2))
|
||||
(factsFn [(factsVar 1) factsAny] (factsVar 2))
|
||||
(factsResult (factsVar 0) (factsVar 1))]
|
||||
(factsVar 2))))
|
||||
(factsFact "resultIsOk" factsTrusted
|
||||
(factsForall [0 1]
|
||||
(factsFn [(factsResult (factsVar 0) (factsVar 1))] factsBool)))
|
||||
(factsFact "resultIsErr" factsTrusted
|
||||
(factsForall [0 1]
|
||||
(factsFn [(factsResult (factsVar 0) (factsVar 1))] factsBool)))
|
||||
(factsFact "mapResult" factsTrusted
|
||||
(factsForall [0 1 2]
|
||||
(factsFn
|
||||
[(factsFn [(factsVar 1)] (factsVar 2))
|
||||
(factsResult (factsVar 0) (factsVar 1))]
|
||||
(factsResult (factsVar 0) (factsVar 2)))))
|
||||
(factsFact "bindResult" factsTrusted
|
||||
(factsForall [0 1 2]
|
||||
(factsFn
|
||||
[(factsResult (factsVar 0) (factsVar 1))
|
||||
(factsFn [(factsVar 1)] (factsResult (factsVar 0) (factsVar 2)))]
|
||||
(factsResult (factsVar 0) (factsVar 2)))))
|
||||
(factsFact "resultOr" factsTrusted
|
||||
(factsForall [0 1]
|
||||
(factsFn [(factsVar 1) (factsResult (factsVar 0) (factsVar 1))] (factsVar 1))))
|
||||
(factsFact "resultMapErr" factsTrusted
|
||||
(factsForall [0 1 2]
|
||||
(factsFn
|
||||
[(factsFn [(factsVar 0)] (factsVar 2))
|
||||
(factsResult (factsVar 0) (factsVar 1))]
|
||||
(factsResult (factsVar 2) (factsVar 1)))))]
|
||||
|
||||
148
lib/list.tri
148
lib/list.tri
@@ -291,3 +291,151 @@ zipWith_ self f xs ys =
|
||||
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)))))]
|
||||
|
||||
341
lib/view.tri
341
lib/view.tri
@@ -64,6 +64,9 @@ viewTagMaybe = 4
|
||||
viewTagPair = 5
|
||||
viewTagResult = 6
|
||||
viewTagGuarded = 7
|
||||
viewTagVar = 8
|
||||
viewTagForall = 9
|
||||
viewTagExists = 10
|
||||
viewFieldArgs = 0
|
||||
viewFieldResult = 1
|
||||
viewFieldRef = 2
|
||||
@@ -74,6 +77,9 @@ viewFieldErr = 6
|
||||
viewFieldOk = 7
|
||||
viewFieldBase = 8
|
||||
viewFieldGuard = 9
|
||||
viewFieldVar = 10
|
||||
viewFieldBinders = 11
|
||||
viewFieldBody = 12
|
||||
|
||||
-- Evidence tags
|
||||
evidenceTagTrusted = 0
|
||||
@@ -181,6 +187,11 @@ typedNodeFieldView = 1
|
||||
typedNodeFieldTerm = 2
|
||||
typedNodeFieldCallee = 3
|
||||
typedNodeFieldArg = 4
|
||||
typedNodeFieldProvenance = 5
|
||||
|
||||
viewProvenanceChecked = 0
|
||||
viewProvenanceTrusted = 1
|
||||
viewProvenanceUnchecked = 2
|
||||
|
||||
-- Checked-exec / runtime guard protocol tags. Successful checker results always
|
||||
-- carry checked-exec artifacts; unguarded roots are represented as checkedPure.
|
||||
@@ -227,6 +238,11 @@ viewResult errView okView =
|
||||
record viewTagResult [(field viewFieldErr errView) (field viewFieldOk okView)]
|
||||
viewGuarded baseView guard =
|
||||
record viewTagGuarded [(field viewFieldBase baseView) (field viewFieldGuard guard)]
|
||||
viewVar name = record viewTagVar [(field viewFieldVar name)]
|
||||
viewForall binders body =
|
||||
record viewTagForall [(field viewFieldBinders binders) (field viewFieldBody body)]
|
||||
viewExists binders body =
|
||||
record viewTagExists [(field viewFieldBinders binders) (field viewFieldBody body)]
|
||||
|
||||
viewTag = recordTag
|
||||
viewPayload = recordFields
|
||||
@@ -247,8 +263,14 @@ maybeView? = (view : equal? (viewTag view) viewTagMaybe)
|
||||
pairView? = (view : equal? (viewTag view) viewTagPair)
|
||||
resultView? = (view : equal? (viewTag view) viewTagResult)
|
||||
guardedView? = (view : equal? (viewTag view) viewTagGuarded)
|
||||
varView? = (view : equal? (viewTag view) viewTagVar)
|
||||
forallView? = (view : equal? (viewTag view) viewTagForall)
|
||||
existsView? = (view : equal? (viewTag view) viewTagExists)
|
||||
guardedViewBase = (view : field0 (viewPayload view))
|
||||
guardedViewGuard = (view : field1 (viewPayload view))
|
||||
viewVarName = (view : field0 (viewPayload view))
|
||||
viewBinderNames = (view : field0 (viewPayload view))
|
||||
viewQuantifiedBody = (view : field1 (viewPayload view))
|
||||
|
||||
viewFact = (view evidence :
|
||||
record viewFactTagKnown
|
||||
@@ -313,6 +335,12 @@ wellFormedResultView? = (view :
|
||||
wellFormedGuardedView? = (view :
|
||||
fields2? (viewPayload view) viewFieldBase viewFieldGuard)
|
||||
|
||||
wellFormedVarView? = (view :
|
||||
fields1? (viewPayload view) viewFieldVar)
|
||||
|
||||
wellFormedQuantifiedView? = (view :
|
||||
fields2? (viewPayload view) viewFieldBinders viewFieldBody)
|
||||
|
||||
wellFormedView_ self view =
|
||||
lazyBool
|
||||
(_ : wellFormedAnyView? view)
|
||||
@@ -354,7 +382,23 @@ wellFormedView_ self view =
|
||||
(_ : self (guardedViewBase view))
|
||||
(_ : false)
|
||||
(wellFormedGuardedView? view))
|
||||
(_ : false)
|
||||
(_ :
|
||||
lazyBool
|
||||
(_ : wellFormedVarView? view)
|
||||
(_ :
|
||||
lazyBool
|
||||
(_ :
|
||||
lazyBool
|
||||
(_ : self (viewQuantifiedBody view))
|
||||
(_ : false)
|
||||
(wellFormedQuantifiedView? view))
|
||||
(_ :
|
||||
lazyBool
|
||||
(_ : self (viewQuantifiedBody view))
|
||||
(_ : false)
|
||||
(wellFormedQuantifiedView? view))
|
||||
(forallView? view))
|
||||
(varView? view))
|
||||
(guardedView? view))
|
||||
(and? (resultView? view) (wellFormedResultView? view)))
|
||||
(and? (pairView? view) (wellFormedPairView? view)))
|
||||
@@ -469,6 +513,28 @@ hasView? = (symbol view env :
|
||||
(viewSet : viewSetHas? view viewSet)
|
||||
(lookupViews symbol env))
|
||||
|
||||
viewSetHasCompatible_ self namespace expected viewSet =
|
||||
lazyList
|
||||
(_ : false)
|
||||
(fact rest :
|
||||
lazyMaybe
|
||||
(_ : self namespace expected rest)
|
||||
(_ : true)
|
||||
(matchView expected (instantiateView namespace (viewFactView fact)) t))
|
||||
viewSet
|
||||
|
||||
viewSetHasCompatible? = (namespace expected viewSet :
|
||||
lazyBool
|
||||
(_ : true)
|
||||
(_ : y viewSetHasCompatible_ namespace expected viewSet)
|
||||
(anyView? expected))
|
||||
|
||||
hasCompatibleView? = (symbol view env :
|
||||
lazyMaybe
|
||||
(_ : anyView? view)
|
||||
(viewSet : viewSetHasCompatible? symbol view viewSet)
|
||||
(lookupViews symbol env))
|
||||
|
||||
addViewToSet = (view evidence viewSet :
|
||||
lazyBool
|
||||
(_ : viewSet)
|
||||
@@ -491,19 +557,44 @@ extendEnv_ self symbol view evidence env =
|
||||
extendEnv = (symbol view evidence env :
|
||||
y extendEnv_ symbol view evidence env)
|
||||
|
||||
findFnView_ self viewSet =
|
||||
instantiateVarId = (namespace localId :
|
||||
pair namespace localId)
|
||||
|
||||
instantiateBinders_ self namespace binders subst =
|
||||
lazyList
|
||||
(_ : subst)
|
||||
(binder rest :
|
||||
self namespace rest (pair (pair binder (viewVar (instantiateVarId namespace binder))) subst))
|
||||
binders
|
||||
|
||||
instantiateBinders = (namespace binders subst :
|
||||
y instantiateBinders_ namespace binders subst)
|
||||
|
||||
instantiateView = (namespace view :
|
||||
lazyBool
|
||||
(_ : substituteView (instantiateBinders namespace (viewBinderNames view) t) (viewQuantifiedBody view))
|
||||
(_ : view)
|
||||
(forallView? view))
|
||||
|
||||
viewAsFn = (namespace view :
|
||||
let instantiated = instantiateView namespace view in
|
||||
lazyBool
|
||||
(_ : just instantiated)
|
||||
(_ : nothing)
|
||||
(fnView? instantiated))
|
||||
|
||||
findFnView_ self namespace viewSet =
|
||||
lazyList
|
||||
(_ : nothing)
|
||||
(fact rest :
|
||||
let view = viewFactView fact in
|
||||
lazyBool
|
||||
(_ : just view)
|
||||
lazyMaybe
|
||||
(_ : self rest)
|
||||
(fnView? view))
|
||||
(fnView : just fnView)
|
||||
(viewAsFn namespace (viewFactView fact)))
|
||||
viewSet
|
||||
|
||||
findFnView = (viewSet :
|
||||
y findFnView_ viewSet)
|
||||
findFnView = (namespace viewSet :
|
||||
y findFnView_ namespace viewSet)
|
||||
|
||||
firstKnownView = (viewSet :
|
||||
lazyList
|
||||
@@ -517,6 +608,156 @@ actualViewFor = (symbol env :
|
||||
(viewSet : firstKnownView viewSet)
|
||||
(lookupViews symbol env))
|
||||
|
||||
substLookup_ self name subst =
|
||||
lazyList
|
||||
(_ : nothing)
|
||||
(entry rest :
|
||||
lazyBool
|
||||
(_ : just (snd entry))
|
||||
(_ : self name rest)
|
||||
(equal? name (fst entry)))
|
||||
subst
|
||||
|
||||
substLookup = (name subst : y substLookup_ name subst)
|
||||
|
||||
substBind = (name actual subst :
|
||||
lazyBool
|
||||
(_ : just subst)
|
||||
(_ :
|
||||
lazyBool
|
||||
(_ : just subst)
|
||||
(_ :
|
||||
lazyMaybe
|
||||
(_ : just (pair (pair name actual) subst))
|
||||
(existing :
|
||||
lazyBool
|
||||
(_ : just subst)
|
||||
(_ : nothing)
|
||||
(equal? existing actual))
|
||||
(substLookup name subst))
|
||||
(varView? actual))
|
||||
(equal? actual (viewVar name)))
|
||||
|
||||
substituteView_ self subst view =
|
||||
lazyBool
|
||||
(_ :
|
||||
lazyMaybe
|
||||
(_ : view)
|
||||
(bound : self subst bound)
|
||||
(substLookup (viewVarName view) subst))
|
||||
(_ :
|
||||
lazyBool
|
||||
(_ : viewFn (y substituteViews_ self subst (fnArgs view)) (self subst (fnResult view)))
|
||||
(_ :
|
||||
lazyBool
|
||||
(_ : viewList (self subst (field0 (viewPayload view))))
|
||||
(_ :
|
||||
lazyBool
|
||||
(_ : viewMaybe (self subst (field0 (viewPayload view))))
|
||||
(_ :
|
||||
lazyBool
|
||||
(_ : viewPair (self subst (field0 (viewPayload view))) (self subst (field1 (viewPayload view))))
|
||||
(_ :
|
||||
lazyBool
|
||||
(_ : viewResult (self subst (field0 (viewPayload view))) (self subst (field1 (viewPayload view))))
|
||||
(_ :
|
||||
lazyBool
|
||||
(_ : viewGuarded (self subst (guardedViewBase view)) (guardedViewGuard view))
|
||||
(_ : view)
|
||||
(guardedView? view))
|
||||
(resultView? view))
|
||||
(pairView? view))
|
||||
(maybeView? view))
|
||||
(listView? view))
|
||||
(fnView? view))
|
||||
(varView? view)
|
||||
|
||||
substituteViews_ self viewSelf subst views =
|
||||
lazyList
|
||||
(_ : t)
|
||||
(view rest : pair (viewSelf subst view) (self viewSelf subst rest))
|
||||
views
|
||||
|
||||
substituteView = (subst view : y substituteView_ subst view)
|
||||
|
||||
matchViewList_ self matchSelf expected actual subst =
|
||||
lazyList
|
||||
(_ :
|
||||
lazyList
|
||||
(_ : just subst)
|
||||
(_ _ : nothing)
|
||||
actual)
|
||||
(expectedHead expectedRest :
|
||||
lazyList
|
||||
(_ : nothing)
|
||||
(actualHead actualRest :
|
||||
lazyMaybe
|
||||
(_ : nothing)
|
||||
(nextSubst : self matchSelf expectedRest actualRest nextSubst)
|
||||
(matchSelf expectedHead actualHead subst))
|
||||
actual)
|
||||
expected
|
||||
|
||||
matchView_ self expected actual subst =
|
||||
lazyBool
|
||||
(_ : just subst)
|
||||
(_ :
|
||||
lazyBool
|
||||
(_ : substBind (viewVarName expected) actual subst)
|
||||
(_ :
|
||||
lazyBool
|
||||
(_ : substBind (viewVarName actual) expected subst)
|
||||
(_ :
|
||||
lazyBool
|
||||
(_ : just subst)
|
||||
(_ :
|
||||
lazyBool
|
||||
(_ :
|
||||
lazyMaybe
|
||||
(_ : nothing)
|
||||
(argSubst : self (fnResult expected) (fnResult actual) argSubst)
|
||||
(y matchViewList_ self (fnArgs expected) (fnArgs actual) subst))
|
||||
(_ :
|
||||
lazyBool
|
||||
(_ : self (field0 (viewPayload expected)) (field0 (viewPayload actual)) subst)
|
||||
(_ :
|
||||
lazyBool
|
||||
(_ : self (field0 (viewPayload expected)) (field0 (viewPayload actual)) subst)
|
||||
(_ :
|
||||
lazyBool
|
||||
(_ :
|
||||
lazyMaybe
|
||||
(_ : nothing)
|
||||
(leftSubst : self (field1 (viewPayload expected)) (field1 (viewPayload actual)) leftSubst)
|
||||
(self (field0 (viewPayload expected)) (field0 (viewPayload actual)) subst))
|
||||
(_ :
|
||||
lazyBool
|
||||
(_ :
|
||||
lazyMaybe
|
||||
(_ : nothing)
|
||||
(errSubst : self (field1 (viewPayload expected)) (field1 (viewPayload actual)) errSubst)
|
||||
(self (field0 (viewPayload expected)) (field0 (viewPayload actual)) subst))
|
||||
(_ :
|
||||
lazyBool
|
||||
(_ : self (guardedViewBase expected) actual subst)
|
||||
(_ :
|
||||
lazyBool
|
||||
(_ : self expected (guardedViewBase actual) subst)
|
||||
(_ : nothing)
|
||||
(guardedView? actual))
|
||||
(guardedView? expected))
|
||||
(and? (resultView? expected) (resultView? actual)))
|
||||
(and? (pairView? expected) (pairView? actual)))
|
||||
(and? (maybeView? expected) (maybeView? actual)))
|
||||
(and? (listView? expected) (listView? actual)))
|
||||
(and? (fnView? expected) (fnView? actual)))
|
||||
(equal? expected actual))
|
||||
(varView? actual))
|
||||
(varView? expected))
|
||||
(anyView? expected)
|
||||
|
||||
matchView = (expected actual subst : y matchView_ expected actual subst)
|
||||
|
||||
checkerErr = (tag fields env : err (diagnostic tag fields) env)
|
||||
checkerOk = (env : ok env t)
|
||||
|
||||
@@ -548,15 +789,26 @@ checkApplicationSymbols = (policy argSymbol outSymbol env fnView :
|
||||
lazyList
|
||||
(_ : checkerErr errorTagZeroArityFunction t env)
|
||||
(argView restArgs :
|
||||
let resultView = fnResidual restArgs (fnResult fnView) in
|
||||
lazyBool
|
||||
(_ : checkerOk (extendEnv outSymbol resultView evidenceTagInferred env))
|
||||
let actualView = instantiateView argSymbol (actualViewFor argSymbol env) in
|
||||
lazyMaybe
|
||||
(_ :
|
||||
lazyResult
|
||||
(diag envAtError : err diag envAtError)
|
||||
(nextEnv _ : checkerOk (extendEnv outSymbol resultView evidenceTagInferred nextEnv))
|
||||
(nextEnv _ : checkerOk (extendEnv outSymbol (fnResidual restArgs (fnResult fnView)) evidenceTagInferred nextEnv))
|
||||
(missingArgumentOrGuardedBase policy argSymbol argView env))
|
||||
(hasView? argSymbol argView env))
|
||||
(subst :
|
||||
let nextEnv =
|
||||
lazyBool
|
||||
(_ : extendEnv argSymbol argView evidenceTagRequired env)
|
||||
(_ : env)
|
||||
(guardedView? argView) in
|
||||
checkerOk
|
||||
(extendEnv
|
||||
outSymbol
|
||||
(substituteView subst (fnResidual restArgs (fnResult fnView)))
|
||||
evidenceTagInferred
|
||||
nextEnv))
|
||||
(matchView argView actualView t))
|
||||
(fnArgs fnView))
|
||||
|
||||
-- ---------------------------------------------------------------------------
|
||||
@@ -571,6 +823,13 @@ typedProgram = (root nodes :
|
||||
typedProgramRoot = (program : field0 (recordFields program))
|
||||
typedProgramNodes = (program : field1 (recordFields program))
|
||||
|
||||
typedValueWithProvenance = (symbol view term provenance :
|
||||
record typedNodeTagValue
|
||||
[(field typedNodeFieldSymbol symbol)
|
||||
(field typedNodeFieldView view)
|
||||
(field typedNodeFieldTerm term)
|
||||
(field typedNodeFieldProvenance provenance)])
|
||||
|
||||
typedValue = (symbol view term :
|
||||
record typedNodeTagValue
|
||||
[(field typedNodeFieldSymbol symbol)
|
||||
@@ -584,6 +843,13 @@ typedApply = (symbol callee arg term :
|
||||
(field typedNodeFieldArg arg)
|
||||
(field typedNodeFieldTerm term)])
|
||||
|
||||
typedRequireWithProvenance = (symbol view term provenance :
|
||||
record typedNodeTagRequire
|
||||
[(field typedNodeFieldSymbol symbol)
|
||||
(field typedNodeFieldView view)
|
||||
(field typedNodeFieldTerm term)
|
||||
(field typedNodeFieldProvenance provenance)])
|
||||
|
||||
typedRequire = (symbol view term :
|
||||
record typedNodeTagRequire
|
||||
[(field typedNodeFieldSymbol symbol)
|
||||
@@ -597,11 +863,23 @@ typedApplyCallee = (node : field1 (recordFields node))
|
||||
typedApplyArg = (node : field2 (recordFields node))
|
||||
typedApplyTerm = (node : field0 (tail (tail (tail (recordFields node)))))
|
||||
|
||||
wellFormedViewProvenance? = (provenance :
|
||||
or?
|
||||
(or? (equal? provenance viewProvenanceChecked) (equal? provenance viewProvenanceTrusted))
|
||||
(equal? provenance viewProvenanceUnchecked))
|
||||
|
||||
wellFormedTypedViewFactFields? = (fields :
|
||||
or?
|
||||
(fields3? fields typedNodeFieldSymbol typedNodeFieldView typedNodeFieldTerm)
|
||||
(and?
|
||||
(fields4? fields typedNodeFieldSymbol typedNodeFieldView typedNodeFieldTerm typedNodeFieldProvenance)
|
||||
(wellFormedViewProvenance? (field3 fields))))
|
||||
|
||||
wellFormedTypedValue? = (node :
|
||||
lazyBool
|
||||
(_ : wellFormedView? (typedNodeView node))
|
||||
(_ : false)
|
||||
(fields3? (recordFields node) typedNodeFieldSymbol typedNodeFieldView typedNodeFieldTerm))
|
||||
(wellFormedTypedViewFactFields? (recordFields node)))
|
||||
|
||||
wellFormedTypedApply? = (node :
|
||||
fields3? (recordFields node) typedNodeFieldSymbol typedNodeFieldCallee typedNodeFieldArg)
|
||||
@@ -619,7 +897,7 @@ wellFormedTypedRequire? = (node :
|
||||
lazyBool
|
||||
(_ : wellFormedView? (typedNodeView node))
|
||||
(_ : false)
|
||||
(fields3? (recordFields node) typedNodeFieldSymbol typedNodeFieldView typedNodeFieldTerm))
|
||||
(wellFormedTypedViewFactFields? (recordFields node)))
|
||||
|
||||
wellFormedTypedNode? = (node :
|
||||
let tag = recordTag node in
|
||||
@@ -686,7 +964,7 @@ checkTypedRequireNode = (policy node env :
|
||||
(hasView? symbol (guardedViewBase view) env))
|
||||
(_ : missingRequiredView policy symbol view env)
|
||||
(guardedView? view))
|
||||
(hasView? symbol view env))
|
||||
(hasCompatibleView? symbol view env))
|
||||
|
||||
missingArgumentOrGuardedBase = (policy symbol view env :
|
||||
lazyBool
|
||||
@@ -705,7 +983,7 @@ checkTypedApplyNode = (policy node env :
|
||||
lazyMaybe
|
||||
(_ : checkerOk env)
|
||||
(fnView : checkApplicationSymbols policy (typedApplyArg node) (typedNodeSymbol node) env fnView)
|
||||
(findFnView calleeViews))
|
||||
(findFnView (typedApplyCallee node) calleeViews))
|
||||
(lookupViews (typedApplyCallee node) env))
|
||||
|
||||
checkTypedNode = (policy node env :
|
||||
@@ -1111,6 +1389,18 @@ renderViewArgs_ self viewSelf views =
|
||||
(emptyList? rest))
|
||||
views
|
||||
|
||||
renderBinders_ self binders =
|
||||
lazyList
|
||||
(_ : "")
|
||||
(binder rest :
|
||||
lazyBool
|
||||
(_ : binder)
|
||||
(_ : append binder (append ", " (self rest)))
|
||||
(emptyList? rest))
|
||||
binders
|
||||
|
||||
renderBinders = (binders : y renderBinders_ binders)
|
||||
|
||||
renderView_ self view =
|
||||
lazyBool
|
||||
(_ : "Bool")
|
||||
@@ -1162,7 +1452,19 @@ renderView_ self view =
|
||||
(_ :
|
||||
lazyBool
|
||||
(_ : append "Guarded " (self (guardedViewBase view)))
|
||||
(_ : "View")
|
||||
(_ :
|
||||
lazyBool
|
||||
(_ : append "$" (showNumber (viewVarName view)))
|
||||
(_ :
|
||||
lazyBool
|
||||
(_ : append "forall [" (append (renderBinders (viewBinderNames view)) (append "] " (self (viewQuantifiedBody view)))) )
|
||||
(_ :
|
||||
lazyBool
|
||||
(_ : append "exists [" (append (renderBinders (viewBinderNames view)) (append "] " (self (viewQuantifiedBody view)))) )
|
||||
(_ : "View")
|
||||
(existsView? view))
|
||||
(forallView? view))
|
||||
(varView? view))
|
||||
(guardedView? view))
|
||||
(fnView? view))
|
||||
(resultView? view))
|
||||
@@ -1460,12 +1762,15 @@ viewContractSelfTests = [
|
||||
(viewContractProbe (wellFormedView? (viewPair viewBool viewString)))
|
||||
(viewContractProbe (wellFormedView? (viewResult viewString viewBool)))
|
||||
(viewContractProbe (wellFormedView? (viewGuarded viewString (x : x))))
|
||||
(viewContractProbe (wellFormedView? (viewVar 0)))
|
||||
(viewContractProbe (wellFormedView? (viewForall [(0)] (viewFn [(viewVar 0)] (viewVar 0)))))
|
||||
(viewContractProbe (equal? (renderView viewBool) "Bool"))
|
||||
(viewContractProbe (equal? (renderView (viewList viewBool)) "List Bool"))
|
||||
(viewContractProbe (equal? (renderView (viewMaybe viewString)) "Maybe String"))
|
||||
(viewContractProbe (equal? (renderView (viewPair viewBool viewString)) "Pair Bool String"))
|
||||
(viewContractProbe (equal? (renderView (viewResult viewString viewBool)) "Result String Bool"))
|
||||
(viewContractProbe (equal? (renderView (viewGuarded viewString (x : x))) "Guarded String"))
|
||||
(viewContractProbe (equal? (renderView (viewVar 0)) "$0"))
|
||||
(viewContractProbe (equal? (renderView (viewFn [(viewBool) (viewString)] viewUnit)) "Fn [Bool, String] Unit"))
|
||||
(viewContractProbe (not? (wellFormedView? 10)))
|
||||
(viewContractProbe (not? (wellFormedView? (record viewTagList [(field 99 viewBool)]))))
|
||||
|
||||
Reference in New Issue
Block a user