cakeml icon indicating copy to clipboard operation
cakeml copied to clipboard

Add support for loops

Open charguer opened this issue 6 years ago • 0 comments

Loops can be encoded using tail-ref functions. Yet, they are incredibly useful in the surface language. Especially for describing algorithms. Many graph algorithms take the form while not (queue.is_empty()) do let x = queue.pop() in ...done. In fact, there are also idiomatic programming pattern using break and continue that are pretty ugly to encode without these constructs. A typical example is an early exit from a Dijkstra traversal, e.g.: ... if x = target_vertex then break; ... Break and continue can be encoded using exception, but again that's not pretty.

Presenting formalization of algorithms to researchers in that field without a standard loop syntax is a no-go. Furthermore, there are nice high-level reasoning rules that apply to many loop patterns.

I thus encourage adding loops as well as some form of break/continue in the source language.

The compiler could either treat them directly using goto-s, or try to compile them into tail-rec functions with exceptions for break and continue, then eliminate the closure and the try-catch. Whatever is most convenient.

charguer avatar Jul 02 '19 14:07 charguer