leanfran

package module
v0.9.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 24, 2026 License: Apache-2.0 Imports: 9 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

leanfran for Go

This repository mirrors the Go module from conao3/lean-leanfran, where development, issues, and pull requests live.

Embed Lean definitions and proofs in a Go package. go tool leanfran sync checks the Lean and generates Go functions and types in the same package.

package arithmetic

import "github.com/conao3/leanfran-go"

var _ = leanfran.Lean(`
def twice (n : Nat) : Nat := n + n

theorem twice_ge (n : Nat) : n ≤ twice n := by
  unfold twice
  omega
`)

With Go 1.26 or later, Lean, Lake, and leanfran-go available, run the following from the application module.

go get github.com/conao3/leanfran-go
go get -tool github.com/conao3/leanfran-go/cmd/leanfran
go tool leanfran sync

Go callers can now use arithmetic.Twice(big.NewInt(21)). Commit the generated Go and manifest so the application can build with Go alone.

Verify a Go function

Add //leanfran:model refines=nibbleSpec ensures=in_range:inRange to a top-level Go function. Define the executable specifications in a Lean block and prove the generated obligations under lean/Proofs/.

go tool leanfran check --require proved
go test ./...

The nibble sample checks a bit mask against a remainder, and the clamp sample checks a clamp against an independently written specification. See Verify a Go function in Lean for the directive, proof states, and supported Go syntax.

Build the compiler with nix build .#go from the leanfran source checkout. The range sample includes a Lean structure, a theorem, and a Go caller. The Go guide covers configuration, importing Go models, generated packages, and JSON Schema. See Go development for building and testing the backend.

Documentation

Index

Constants

View Source
const GeneratorVersion = 6
View Source
const Version = "0.9.0"

Variables

This section is empty.

Functions

func CheckAt

func CheckAt[T any](e *ValidationError, c Codec[T], value T, path ...any)

func Ctor

func Ctor(tag uint16, values ...rt.V) rt.V

func MarshalJSON

func MarshalJSON[T any](c Codec[T], value T, path ...any) ([]byte, error)

func ReadIO

func ReadIO(result rt.V) (rt.V, error)

func UnmarshalJSON

func UnmarshalJSON[T any](c Codec[T], data []byte, path ...any) (T, error)

func Validate

func Validate[T any](c Codec[T], value T, path ...any) error

func Zero

func Zero[T any]() (zero T)

Types

type Block

type Block struct{}

func Lean

func Lean(string, ...BlockOption) Block

func LeanFile

func LeanFile(string, ...BlockOption) Block

type BlockOption

type BlockOption struct{}

func Imports

func Imports(...string) BlockOption

func Models

func Models(...any) BlockOption

func Uses

func Uses(...string) BlockOption

type Codec

type Codec[T any] struct {
	Desc     *schema.Desc
	ToLean   func(T) rt.V
	FromLean func(rt.V) T
	Check    func(*ValidationError, T)
}

func Big

func Big(kind string, bound string) Codec[*big.Int]

func Bool

func Bool() Codec[bool]

func Char

func Char() Codec[rune]

func Fin

func Fin(bound string) Codec[uint64]

func Fixed

func Fixed[T fixed](kind string, bits int) Codec[T]

func Option

func Option[T any](item Codec[T]) Codec[*T]

func Product

func Product[A, B any](a Codec[A], b Codec[B]) Codec[Pair[A, B]]

func Ref

func Ref[T any](desc func() *schema.Desc, to func(T) rt.V, from func(rt.V) T, check func(*ValidationError, T)) Codec[T]

func Result

func Result[E, A any](e Codec[E], a Codec[A]) Codec[Except[E, A]]

func Scalar

func Scalar[T any](kind string, bits int, to func(T) rt.V, from func(rt.V) T) Codec[T]

func Sequence

func Sequence[T any](kind string, item Codec[T]) Codec[[]T]

func String

func String() Codec[string]

func Unit

func Unit() Codec[struct{}]

type Except

type Except[E, A any] struct {
	Error *E
	Ok    A
}

type ExceptError

type ExceptError[E any] struct {
	Value E
}

func (*ExceptError[E]) Error

func (e *ExceptError[E]) Error() string

type IOError

type IOError struct {
	Message string
}

func (*IOError) Error

func (e *IOError) Error() string

type Issue

type Issue struct {
	Message string
	Path    []any
}

type Pair

type Pair[A, B any] struct {
	Fst A
	Snd B
}

type ValidationError

type ValidationError struct {
	Issues []Issue
}

func (*ValidationError) Add

func (e *ValidationError) Add(message string, path ...any)

func (*ValidationError) Err

func (e *ValidationError) Err() error

func (*ValidationError) Error

func (e *ValidationError) Error() string

func (*ValidationError) Prefix

func (e *ValidationError) Prefix(start int, path ...any)

Directories

Path Synopsis
cmd
leanfran command
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL