Categorygithub.com/chewxy/hm
modulepackage
1.0.0
Repository: https://github.com/chewxy/hm.git
Documentation: pkg.go.dev

# README

hm GoDoc Build Status Coverage Status

Package hm is a simple Hindley-Milner type inference system in Go. It provides the necessary data structures and functions for creating such a system.

Installation

This package is go-gettable: go get -u github.com/chewxy/hm

There are very few dependencies that this package uses. Therefore there isn't a need for vendoring tools. However, package hm DOES provide a Gopkg.toml and Gopkg.lock for any potential users of the dep tool.

Here is a listing of the dependencies of hm:

PackageUsed ForVitalityNotesLicence
errorsError wrappingCan do without, but this is by far the superior error solution out thereStable API for the past 6 monthserrors licence (MIT/BSD-like)
testify/assertTestingCan do without but will be a massive pain in the ass to testtestify licence (MIT/BSD-like)

Usage

TODO: Write this

Notes

This package is used by Gorgonia as part of the graph building process. It is also used by several other internal projects of this author, all sharing a similar theme of requiring a type system, which is why this was abstracted out.

Contributing

This library is developed using Github. Therefore the workflow is very github-centric.

Licence

Package hm is licenced under the MIT licence.

# Functions

BorrowMSubs gets a map based substitution from a shared pool.
BorrowSSubs gets a slice based substituiton from a shared pool.
BorrowTypes gets a slice of Types with size.
BorrowTypeVarSet gets a TypeVarSet of size from pool.
Generalize takes an env and a type and creates the most general possible type - which is a polytype Generalization If ..
Infer takes an env, and an expression, and returns a scheme.
Instantiate takes a fresh name generator, an a polytype and makes a concrete type out of it.
NewFnType creates a new FunctionType.
NewRecordType creates a new Record Type.
No description provided by the author
ReturnFnType returns a *FunctionType to the pool.
ReturnSubs returns substitutions to the pool.
ReturnTypes returns the slice of types into the pool.
ReturnTypeVarSet returns the TypeVarSet to pool.
Unify unifies the two types and returns a list of substitutions.

# Structs

A Constraint is well.
FunctionType is a type constructor that builds function types.
Record is a basic record/tuple type.
Scheme represents a polytype.
A Substitution is a tuple representing the TypeVariable and the replacement Type.

# Interfaces

Apply is an Expression/AST node that represents a function application.
Cloner is any type that can clone.
An Env is essentially a map of names to schemes.
An Expression is basically an AST node.
Fresher keeps track of all the TypeVariables that has been generated so far.
An Inferer is an Expression that can infer its own Type given an Env.
Lambda is an Expression/AST node that represents a function definiton.
Let is an Expression/AST node that represents the standard let polymorphism found in functional languages.
LetRec is an Expression/AST node that represents a recursive let.
Literal is an Expression/AST Node representing a literal.
A Namer is anything that knows its own name.
Subs is a list of substitution.
Substitutable is any type that can have a set of substitutions applied on it, as well as being able to know what its free type variables are.
Type represents all the possible type constructors.
A Typer is an Expression node that knows its own Type.
Var is an expression representing a variable.

# Type aliases

Constraints is a slice of Constraint.
No description provided by the author
TypeConst are the default implementation of a constant type.
Types is a slice of Type.
TypeVariable is a variable that ranges over the types - that is to say it can take any type.
TypeVarSet is a set of TypeVariable.