/usr/share/minlog/lib/tsil.scm is in minlog 4.0.99.20100221-6.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 | ; tsil.scm
; Constructors: Lin, Snoc
; Constants: Append displayed as :+:, Lh, Proj displayed as __, Lead, Last
(if (not (assoc "nat" ALGEBRAS))
(myerror "First execute (load \"~/minlog/lib/nat.scm\")"))
(display "loading tsil.scm ...") (newline)
(add-param-alg "tsil" 'prefix-typeop
'("Lin" "tsil")
'("Snoc" "tsil=>alpha1=>tsil"))
; Infix notation allowed (and type parameters omitted) for binary
; constructors, as follows. This would also work for prefix notation.
; Example: :: for Cons. x::y::z:
(add-token
"::"
'pair-op
(lambda (xs x)
(let* ((type (term-to-type x))
(listtype (term-to-type xs)))
(if (and (alg-form? listtype)
(string=? "tsil" (alg-form-to-name listtype))
(equal? type (car (alg-form-to-types listtype))))
(mk-term-in-app-form
(make-term-in-const-form
(let* ((constr (constr-name-to-constr "Snoc"))
(tvars (const-to-tvars constr))
(subst (make-substitution tvars (list type))))
(const-substitute constr subst #f)))
xs x)
(myerror "parse error: types do not fit for"
(type-to-string listtype)
"::"
(type-to-string type))))))
(add-display
(py "tsil alpha")
(lambda (x)
(let* ((op (term-in-app-form-to-final-op x))
(args (term-in-app-form-to-args x)))
(if (and (term-in-const-form? op)
(string=? "Snoc"
(const-to-name (term-in-const-form-to-const op)))
(= 2 (length args)))
(list 'pair-op "::"
(term-to-token-tree (car args))
(term-to-token-tree (cadr args)))
#f))))
(add-token
":"
'prefix-op
(lambda (x)
(mk-term-in-app-form
(make-term-in-const-form
(let* ((constr (constr-name-to-constr "Snoc"))
(tvars (const-to-tvars constr))
(subst (make-substitution tvars (list (term-to-type x)))))
(const-substitute constr subst #f)))
(make-term-in-const-form
(let* ((constr (constr-name-to-constr "Lin"))
(tvars (const-to-tvars constr))
(subst (make-substitution tvars (list (term-to-type x)))))
(const-substitute constr subst #f)))
x)))
(add-display
(py "tsil alpha")
(lambda (x)
(let* ((op (term-in-app-form-to-final-op x))
(args (term-in-app-form-to-args x)))
(if (and (term-in-const-form? op)
(string=? "Snoc" (const-to-name
(term-in-const-form-to-const op)))
(= 2 (length args))
(term-in-const-form? (cadr (reverse args)))
(string=? "Lin" (const-to-name
(term-in-const-form-to-const
(cadr (reverse args))))))
(list 'prefix-op ":" (term-to-token-tree (car (reverse args))))
#f))))
(add-program-constant "TsilAppend"
(py "tsil alpha => tsil alpha => tsil alpha")
1 'const 2)
(add-token
":+:"
'mul-op
(lambda (x y)
(mk-term-in-app-form
(make-term-in-const-form
(let* ((const (pconst-name-to-pconst "TsilAppend"))
(tvars (const-to-tvars const))
(listtype (term-to-type x))
(type (car (alg-form-to-types listtype)))
(subst (make-substitution tvars (list type))))
(const-substitute const subst #f)))
x y)))
(add-display
(py "tsil alpha")
(lambda (x)
(let* ((op (term-in-app-form-to-final-op x))
(args (term-in-app-form-to-args x)))
(if (and (term-in-const-form? op)
(string=? "TsilAppend"
(const-to-name (term-in-const-form-to-const op)))
(= 2 (length args)))
(list 'mul-op ":+:"
(term-to-token-tree (car args))
(term-to-token-tree (cadr args)))
#f))))
(add-computation-rule
(pt "(tsil alpha)_1:+:(Lin alpha)")
(pt "(tsil alpha)_1"))
(add-computation-rule
(pt "(tsil alpha)_1 :+:((tsil alpha)_2::(alpha)_3)")
(pt "(tsil alpha)_1:+:(tsil alpha)_2::(alpha)_3"))
(add-program-constant "TsilLength" (py "tsil alpha => nat") 1 'const 1)
(add-token
"Lh" 'prefix-op
(lambda (x) (make-term-in-app-form
(make-term-in-const-form
(let* ((const (pconst-name-to-pconst "TsilLength"))
(tvars (const-to-tvars const))
(listtype (term-to-type x))
(type (car (alg-form-to-types listtype)))
(subst (make-substitution tvars (list type))))
(const-substitute const subst #f)))
x)))
(add-display
(py "nat")
(lambda (x)
(if (term-in-app-form? x)
(let ((op (term-in-app-form-to-op x)))
(if (and (term-in-const-form? op)
(string=? "TsilLength"
(const-to-name (term-in-const-form-to-const op))))
(list 'prefix-op "Lh"
(term-to-token-tree (term-in-app-form-to-arg x)))
#f))
#f)))
(add-computation-rule (pt "Lh(Lin alpha)") (pt "0"))
(add-computation-rule (pt "Lh(tsil alpha::alpha)") (pt "++ Lh tsil alpha"))
(add-rewrite-rule
(pt "Lh((tsil alpha)_1 :+: (tsil alpha)_2)")
(pt "Lh(tsil alpha)_1+Lh(tsil alpha)_2"))
;projection: if t=[t_0,...,t_{n-1}] (proj t i) yields t_i
;note that proj t n should only be used for n<=Length t
(add-program-constant "TsilProj" (py "tsil alpha => nat => alpha") 1 'const 2)
(add-token
"__"
'mul-op
(lambda (x y)
(mk-term-in-app-form
(make-term-in-const-form
(let* ((const (pconst-name-to-pconst "TsilProj"))
(tvars (const-to-tvars const))
(listtype (term-to-type x))
(type (car (alg-form-to-types listtype)))
(subst (make-substitution tvars (list type))))
(const-substitute const subst #f)))
x y)))
(add-display
(py "alpha")
(lambda (x)
(let* ((op (term-in-app-form-to-final-op x))
(args (term-in-app-form-to-args x)))
(if (and (term-in-const-form? op)
(string=? "TsilProj"
(const-to-name (term-in-const-form-to-const op)))
(= 2 (length args)))
(list 'mul-op "__"
(term-to-token-tree (car args))
(term-to-token-tree (cadr args)))
#f))))
(add-computation-rule (pt "((tsil alpha)_1::alpha)__n")
(pt "[if (n=Lh (tsil alpha)_1) alpha
((tsil alpha)_1__n)]"))
(add-program-constant "TsilLead" (mk-arrow (py "tsil alpha")
(py "tsil alpha")) 1 'const 1)
(add-program-constant "TsilLast" (mk-arrow (py "tsil alpha")
(py "alpha")) 1 'const 1)
(add-token
"Lead" 'prefix-op
(lambda (x) (make-term-in-app-form
(make-term-in-const-form
(let* ((const (pconst-name-to-pconst "TsilLead"))
(tvars (const-to-tvars const))
(listtype (term-to-type x))
(type (car (alg-form-to-types listtype)))
(subst (make-substitution tvars (list type))))
(const-substitute const subst #f)))
x)))
(add-display
(py "alpha")
(lambda (x)
(if (term-in-app-form? x)
(let ((op (term-in-app-form-to-op x)))
(if (and (term-in-const-form? op)
(string=? "TsilLead"
(const-to-name (term-in-const-form-to-const op))))
(list 'prefix-op "Lead"
(term-to-token-tree (term-in-app-form-to-arg x)))
#f))
#f)))
(add-token
"Last" 'prefix-op
(lambda (x) (make-term-in-app-form
(make-term-in-const-form
(let* ((const (pconst-name-to-pconst "TsilLast"))
(tvars (const-to-tvars const))
(listtype (term-to-type x))
(type (car (alg-form-to-types listtype)))
(subst (make-substitution tvars (list type))))
(const-substitute const subst #f)))
x)))
(add-display
(py "alpha")
(lambda (x)
(if (term-in-app-form? x)
(let ((op (term-in-app-form-to-op x)))
(if (and (term-in-const-form? op)
(string=? "TsilLast"
(const-to-name (term-in-const-form-to-const op))))
(list 'prefix-op "Last"
(term-to-token-tree (term-in-app-form-to-arg x)))
#f))
#f)))
(add-computation-rule (pt "Lead (Lin alpha)") (pt "(Lin alpha)")) ;!
(add-computation-rule (pt "Lead ((tsil alpha)_1::alpha_2)")
(pt "(tsil alpha)_1"))
; (add-computation-rule (pt "Last (Lin alpha)")
; (type-to-canonical-inhabitant (py "alpha")))
(add-computation-rule (pt "Last ((tsil alpha)_1::alpha_2)")
(pt "alpha_2"))
(add-program-constant "TsilMap"
(py "(alpha1 => alpha2) => tsil alpha1 => tsil alpha2")
1 'const 2)
(add-computation-rule
(pt "(TsilMap alpha1 alpha2) (alpha1=>alpha2)_1 (Lin alpha1)")
(pt "(Lin alpha2)"))
(add-computation-rule
(pt "(TsilMap alpha1 alpha2) (alpha1=>alpha2)_1 ((tsil alpha1)_1::alpha1)")
(pt "((TsilMap alpha1 alpha2) (alpha1=>alpha2)_1 (tsil alpha1)_1)::
((alpha1=>alpha2)_1 alpha1)"))
(add-token
"Map"
'prefix-op
(lambda (x)
(mk-term-in-app-form
(make-term-in-const-form
(let* ((const (pconst-name-to-pconst "TsilMap"))
(tvars (const-to-tvars const))
(func-type (term-to-type x))
(types (list (arrow-form-to-arg-type func-type)
(arrow-form-to-val-type func-type)))
(subst (make-substitution tvars types)))
(const-substitute const subst #f)))
x)))
;(dt (nt (pt "Map Pred (Lin nat)")));ok
;(dt (nt (pt "Map Pred ((:2::3)::4)")));ok
; (add-display
; (py "tsil alpha2")
; (lambda (x)
; (let* ((op (term-in-app-form-to-final-op x))
; (args (term-in-app-form-to-args x)))
; (if (and (term-in-const-form? op)
; (string=? "TsilMap"
; (const-to-name (term-in-const-form-to-const op)))
; (= 2 (length args)))
; (list 'prefix-op "Map"
; (term-to-token-tree (car args))
; (term-to-token-tree (cadr args)))
; #f))))
;(av "ll" (py "(tsil nat)"))
;(dt (nt (pt "Map Pred ll"))) ; Map Pred> ???
|