Top-1.7: Constraint solving framework employed by the Helium Compiler.

Safe HaskellSafe-Infered

Top.Types.Primitive

Contents

Description

This module contains a data type to represent (plain) types, some basic functionality for types, and an instance for Show.

Synopsis

Data type definition

type Tps = [Tp]Source

data Tp Source

A data type to represent monotypes. Note that Type is already in use in the Unified Haskell Architecture (UHA) which is used in the Helium compiler

Constructors

TVar Int

The type variables are numbered.

TCon String

A type constant is represented by a string.

TApp Tp Tp

The application of two Top.Types. Not all types that can be constructed are well-formed.

Common types

(.->.) :: Tp -> Tp -> TpSource

Constructs a function type from one type to another. This operator is left associative.

listType :: Tp -> TpSource

For instance, (listType intType) represents [Int]

ioType :: Tp -> TpSource

For instance, (ioType boolType) represents (IO Bool)

tupleType :: Tps -> TpSource

A cathesian product of zero or more Top.Types. For instance, (tupleType []) represents (), and (tupleType [charType, stringType]) represents (Char,String)

voidType :: TpSource

The unit type. A special instance of of tuple type.

Basic functionality

variablesInType :: Tp -> [Int]Source

Returns the list of type variables of a type. (no duplicates)

constantsInType :: Tp -> [String]Source

Returns the list of type constants of a type. (no duplicates)

leftSpine :: Tp -> (Tp, Tps)Source

Returns the left spine of a type. For instance, if type t is Either Bool [Int], then leftSpine t is (Either,[Bool,[Int]]).

functionSpine :: Tp -> (Tps, Tp)Source

Returns the right spine of a function type. For instance, if type t is Int -> (Bool -> String), then functionSpine t is ([Int,Bool],String).

functionSpineOfLength :: Int -> Tp -> (Tps, Tp)Source

Returns the right spine of a function type of a maximal length.

arityOfTp :: Tp -> IntSource

Returns the arity of a type, that is, the number of expected arguments.

priorityOfType :: Tp -> IntSource

The priority of a type, primarily used for the insertion of parentheses in pretty printing.

freezeVariablesInType :: Tp -> TpSource

All the type variables in a type are frozen by turning them into a type constant. The integer numeral is prefixed with an underscore ('_').

unfreezeVariablesInType :: Tp -> TpSource

Recover the type variables that are frozen in a type.

Predicates on types

class HasTypes a whereSource

Methods

getTypes :: a -> TpsSource

changeTypes :: (Tp -> Tp) -> a -> aSource