gomini

package
v0.0.0-...-db99403 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2023 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package gomini is mininikanren in Go implemented using channels.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bind

func Bind(ctx context.Context, stream Stream, g Goal, res Stream)

Bind is the monad bind function for state.

func FailureO

func FailureO(ctx context.Context, s *State, ss Stream)

FailureO is a goal that always returns an empty stream of states.

func Go

func Go(ctx context.Context, w *sync.WaitGroup, f func())

func Mplus

func Mplus(ctx context.Context, s1, s2, res Stream)

Mplus is responsible for merging streams

func Run

func Run[A any](ctx context.Context, s *State, g func(A) Goal) chan any

Run behaves like the default miniKanren run command, but returns a stream of answers

func RunTake

func RunTake[A any](ctx context.Context, n int, s *State, g func(A) Goal) []any

Run behaves like the default miniKanren run command

func SetMaxRoutines

func SetMaxRoutines(ctx context.Context, max int) context.Context

func SuccessO

func SuccessO(ctx context.Context, s *State, ss Stream)

SuccessO is a goal that always returns the input state in the resulting stream of states.

Types

type Goal

type Goal func(context.Context, *State, Stream)

Goal is a function that takes a state and returns a stream of states.

func ConjO

func ConjO(gs ...Goal) Goal

Conjs is a macro that extends conjunction to arbitrary arguments

func DisjO

func DisjO(gs ...Goal) Goal

Disjs is a macro that extends disjunction to arbitrary arguments

func EqualO

func EqualO[A any](x, y A) Goal

EqualO returns a Goal that unifies the input expressions in the output stream.

func ExistO

func ExistO[A any](f func(A) Goal) Goal

Exists expects a function that expects a variable and returns a Goal.

func IfThenElseO

func IfThenElseO(cond, thn, els Goal) Goal

IfThenElseO is a goal that evaluates the second goal if the first goal is successful, otherwise it evaluates the third goal.

type State

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

State is a product of a list of substitutions and a variable counter.

func NewState

func NewState(varCreators ...VarCreator) *State

NewState returns an empty state. Provide optional VarCreator, which is used to give variables printable names for debugging purposes.

func NewVar

func NewVar[A any](s *State) (*State, A)

func (*State) CastVar

func (s *State) CastVar(x any) (Var, bool)

func (*State) Equal

func (s *State) Equal(other *State) bool

func (*State) Get

func (s *State) Get(key Var) (any, bool)

func (*State) Set

func (s *State) Set(key Var, value any) *State

func (*State) String

func (s *State) String() string

String returns a string representation of State.

type Stream

type Stream chan *State

func NewEmptyStream

func NewEmptyStream() Stream

func NewStreamForGoal

func NewStreamForGoal(ctx context.Context, g Goal, s *State) Stream

func (Stream) Close

func (ss Stream) Close()

func (Stream) Read

func (ss Stream) Read(ctx context.Context) (*State, bool)

func (Stream) String

func (ss Stream) String() string

String returns a string representation of a stream of states. Warning: If the list is infinite this function will not terminate.

func (Stream) Write

func (ss Stream) Write(ctx context.Context, s *State) bool

type Var

type Var uintptr

type VarCreator

type VarCreator func(varType any, name string) (any, bool)

VarCreator is a function that creates a variable of a given type and name for debugging purposes.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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