Giter VIP home page Giter VIP logo

cs-project_modal-mini-ml's Introduction

An implementation of (partial) Type Inference for the Modal Mini ML

Disclaimer

This repo corresponds to my 4th year Integrated Masters, Mathematics and Computer Science dissertation. It is not intended to be used outside of this context.

Prerequisites

We assume a full installation of Haskell.

Monomorphic Type Inference

The monomorphic type inference implementation is contained within the Monomorphic module. To use this implementation, add the following imports:

import Monomorphic.Types
import Monomorphic.Terms
import Monomorphic.Context
import qualified Monomorphic.Simple.Inference
import qualified Monomorphic.Annotated.Inference

Types

Types are defined within the Monomorphic.Types sub-module. They are defined closely to their corresponding grammar.

As an example, to construct a type representing a lambda abstraction from a natural number to the unit type, you can write:

(Abstraction Natural Unit)

Or, a pair of identity functions, the left for natural numbers, and the right for units

(Product (Abstraction Natural Natural) (Abstraction Unit Unit))

Terms

Terms are defined within the Monomorphic.Terms sub-module. They are defined closely to their corresponding grammar.

Note

Variables are just strings

Usage

To define the identity for natural numbers function:

(Lambda "x" Natural (Var "x"))

Contexts

Contexts are defined in the sub-module Monomorphic.Contexts. They are defined closely to their corresponding grammar and the cons Haskell operator.

To create a modal context consisting of two variables:

MCons "v" Unit (MCons "u" Natural MEmpty)

Inference

Two inference functions are provided: one simple inference method, which only returns the type, and an annotated one, which returns an annotation tree.

The first is located in the sub-module Monomorphic.Simple.Inference, the second is in Monomorphic.Annotated.Inference.

Once one is chosen, you can infer the type of a term, under some contexts as:

infer MEmpty OEmpty (Anno (Lambda "x" Natural (Var "x")) (Abstraction Natural Natural))

Example Terms

Some example terms are provided in the Monomorphic module.

Polymorphic Type Inference

Similar to the monomorphic inference, except the following imports are required instead:

import Polymorphic.Types
import Polymorphic.Terms
import Polymorphic.Context
import qualified Polymorphic.Simple.Inference

Only simple polymorphic inference has been implemented.

Example Terms

Some example terms are provided in the Polymorphic module.

cs-project_modal-mini-ml's People

Contributors

justaidanp avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.