leanfran

package module
v0.10.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: 12 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.

Nix can install the compiler from any directory.

nix profile install 'github:conao3/lean-leanfran#go'
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 and Lean and Lake from Lean 4.35.0 on your PATH, 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.

The range sample includes a Lean structure, a theorem, and a Go caller. The Go guide covers matching the compiler to the Go module, 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 = 8
View Source
const Version = "0.10.0"

Variables

This section is empty.

Functions

func AcquireValueInputs added in v0.10.0

func AcquireValueInputs(inputs []ValueUse)

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 IntegerIssue added in v0.10.0

func IntegerIssue(x *big.Int, nonnegative bool) string

func LockValues added in v0.10.0

func LockValues()

func MarshalJSON

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

func OwnValueField added in v0.10.0

func OwnValueField(v rt.V, i int) rt.V

func ReadIO

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

func ReadValue added in v0.10.0

func ReadValue[T, G any](codec Codec[G], v Value[T]) G

func SplitValue added in v0.10.0

func SplitValue[A, B any](v ValueInput[PairType[A, B]]) (Value[A], Value[B])

func UnlockValues added in v0.10.0

func UnlockValues()

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 ArrayType added in v0.10.0

type ArrayType[T any] struct {
	// contains filtered or unexported fields
}

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 CharType added in v0.10.0

type CharType struct{}

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 ExceptType added in v0.10.0

type ExceptType[E, A any] struct {
	// contains filtered or unexported fields
}

type FinType added in v0.10.0

type FinType[N any] struct {
	// contains filtered or unexported fields
}

type IOError

type IOError struct {
	Message string
}

func (*IOError) Error

func (e *IOError) Error() string

type ISizeType added in v0.10.0

type ISizeType struct{}

type IntType added in v0.10.0

type IntType struct{}

type Issue

type Issue struct {
	Message string
	Path    []any
}

type ListType added in v0.10.0

type ListType[T any] struct {
	// contains filtered or unexported fields
}

type NatType added in v0.10.0

type NatType struct{}

type OptionType added in v0.10.0

type OptionType[T any] struct {
	// contains filtered or unexported fields
}

type Pair

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

type PairType added in v0.10.0

type PairType[A, B any] struct {
	// contains filtered or unexported fields
}

type USizeType added in v0.10.0

type USizeType struct{}

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)

type Value added in v0.10.0

type Value[T any] struct {
	// contains filtered or unexported fields
}

func NewValue added in v0.10.0

func NewValue[T, G any](codec Codec[G], v G, path string) (Value[T], error)

func WrapValue added in v0.10.0

func WrapValue[T any](raw rt.V) Value[T]

func (Value[T]) Borrow added in v0.10.0

func (v Value[T]) Borrow() ValueInput[T]

func (Value[T]) Close added in v0.10.0

func (v Value[T]) Close()

func (Value[T]) Take added in v0.10.0

func (v Value[T]) Take() ValueInput[T]

type ValueInput added in v0.10.0

type ValueInput[T any] struct {
	// contains filtered or unexported fields
}

func (ValueInput[T]) Use added in v0.10.0

func (v ValueInput[T]) Use() ValueUse

type ValueUse added in v0.10.0

type ValueUse struct {
	// contains filtered or unexported fields
}

func (ValueUse) Lean added in v0.10.0

func (u ValueUse) Lean() rt.V

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