A categorical programming language
Révision | 1edc88bf86dd526d4d1b39bd88a228f8b09e40fa (tree) |
---|---|
l'heure | 2023-10-21 13:52:25 |
Auteur | Corbin <cds@corb...> |
Commiter | Corbin |
Try prototyping type inference for algebras.
I'm really *really* thinking about how to avoid having to write out the
types of the carriers, but I'm not quite seeing how to do it. I'm also
trying to avoid writing out the names of elements of signatures, but I
might have to give up.
@@ -474,6 +474,21 @@ | ||
474 | 474 | (cons (cons name (vector most-recent-template "")) templates)))) |
475 | 475 | (begin (display "Need a name, sorry.") (newline)))) |
476 | 476 | |
477 | +(define (cammy-alg° alg sigs ctx) | |
478 | + (conde | |
479 | + ((nullo alg) (nullo sigs)) | |
480 | + ((fresh (expr d sig p s t) | |
481 | + (conso expr d alg) (conso sig p sigs) (conso s t sig) | |
482 | + (cammy-holes° expr s t ctx) | |
483 | + (cammy-alg° d p ctx))))) | |
484 | + | |
485 | +(define (cammy-display-alg exprs) | |
486 | + (display "Algebra: ") | |
487 | + (display (car (run 1 (q) (fresh (sig ctx) (conso sig ctx q) | |
488 | + (cammy-alg° (map build-holes exprs) sig ctx))))) | |
489 | + (newline)) | |
490 | + | |
491 | + | |
477 | 492 | (define help "Basic usage: Enter a Cammy expression to preview its elements. |
478 | 493 | |
479 | 494 | When an expression is valid, it will be saved to '_'. |
@@ -554,6 +569,7 @@ To write the hive, give a filename explicitly: | ||
554 | 569 | ['save |
555 | 570 | (with-output-to-file (read) (lambda () (write-json hive))) |
556 | 571 | (display "Wrote hive to file.") (newline)] |
572 | + [('alg . exprs) (cammy-display-alg (map lookup exprs))] | |
557 | 573 | ; eof |
558 | 574 | [(? eof-object?) (newline) (display "Peace!") (newline) (exit 0)] |
559 | 575 | ; eval |