Abstract:The Isabelle proof assistant includes a small functional language, which allows users to write and reason about programs. So far, these programs could be extracted into a number of functional languages: Standard ML, OCaml, Scala, and Haskell. This work adds support for Go as a fifth target language for the Code Generator. Unlike the previous targets, Go is not a functional language and encourages code in an imperative style, thus many of the features of Isabelle's language (particularly data types, pattern matching, and type classes) have to be emulated using imperative language constructs in Go. The developed Code Generation is provided as an add-on library that can be simply imported into existing theories.
What problem does this paper attempt to address?
### What problem does this paper attempt to solve?
The main goal of this paper is to add support for the Go programming language to the code generator of Isabelle/HOL. Specifically, it attempts to solve the following problems:
1. **Support for non - functional languages**:
- Isabelle/HOL is a theorem - proving assistant that contains a small functional language internally, allowing users to write and reason about programs. Currently, these programs can be extracted into several functional languages (such as Standard ML, OCaml, Scala, and Haskell). However, Go is a non - functional programming language that encourages writing code in an imperative style. Therefore, it is necessary to simulate Isabelle's functional features (such as data types, pattern matching, and type classes) through imperative language structures in Go.
2. **Bridge the gap between formal verification and practical implementation**:
- Within Giesecke + Devrient, Isabelle is used for formal verification and Go is used for practical development simultaneously, which has led to a "formal gap". To bridge this gap, researchers have developed a code - generation tool from Isabelle to Go, enabling formal programs to be directly converted into Go code that can run in a practical environment.
3. **Handle the differences between functional and imperative languages**:
- As an imperative language, Go is very different from the existing target languages of the Isabelle code generator (which are all functional languages). For example, Go does not have features such as pattern matching and type classes. Therefore, researchers need to design a translation scheme to map the advanced functions in Isabelle to the imperative constructs in Go.
4. **Provide an easily - integratable library**:
- The developed code - generation tool is provided as an additional library and can be easily imported into existing Isabelle theories, thus being convenient for users.
### Key points of the translation scheme
- **Intermediate language Thingol**: Isabelle's code generator first translates definitions into an abstract intermediate language Thingol, and then translates from Thingol to the target language.
- **Shallow embedding**: Translate Thingol programs into Go code through shallow embedding, that is, use a subset of the target language to represent the constructs of the source language.
- **Translation of data types**: Since Go does not support sum types, researchers have designed an encoding scheme to simulate the behavior of sum types with interface types.
- **Translation of pattern matching**: Go has no pattern - matching function, so pattern matching is translated into a series of if - conditional statements and destructor calls.
- **Translation of top - level functions**: Top - level functions can have multiple clauses and perform parameter pattern matching in Thingol, but not in Go. Therefore, all equations must be merged and the pattern matching pushed into a single function body.
Through these methods, researchers have successfully implemented code generation from Isabelle to Go, enabling formal programs to run in a practical environment, thus bridging the gap between formal verification and practical development.