Portability | GHC |
---|---|
Stability | experimental |
Maintainer | hans@hanshoglund.se |
Safe Haskell | None |
This Haskell module defines the Modulo description language. Typically, modules are created
by writing .module
files and using the parser defined in Language.Modulo.Parser, or
the modulo
command-line tool. The abstract syntax tree is given below.
The module language is very simple. Each module consists of a name followed by eventual import declarations, followed by all other declarations. Here is an example module:
module Scl.List { opaque Elem; opaque List; nil : () -> List; cons : (Elem, List) -> List; head : (List) -> Elem; tail : (List) -> List; empty : (List) -> Bool; lenght : (List) -> Int; reverse : (List) -> List; sort : (List) -> List; }
Like C, the module language uses structural typing for pointers and functions, but
nominal typing for structures and unions. Thus in the following example values of type
A
and B
are interchangeable, but values of type C
and D
are not.
type A = Ptr Int type B = Ptr Int type C = struct { x : Int, y : Int } type D = struct { x : Int, y : Int }
The pointer type constructor can be used with any type:
type IntPtr = Int* type FloatPtr = Float*
The array type constructor need an explicit length:
type IntVec = [Int x 10]
Functions are written as in Haskell, except for the parentheses enclosing the arguments. Thus, higher-arity functions are easily distinguished.
type NoCurry = (A, B) -> C type Curry = (A) -> (B) -> C
Compound types are written in a uniform manner:
type IntCounter = struct { a : Int, b : Int -> Int } type NumValue = union { left : Int, right : Float } type Color = enum { Red, Green, Blue }
The following primitive types are provided:
Void Size Ptrdiff Intptr UIntptr Char Short Int Long LongLong UChar UShort UInt ULong ULongLong Float Double LongDouble Int8 Int16 Int32 Int64 UInt8 UInt16 UInt32 UInt64
- data Module = Module {
- modName :: ModuleName
- modImports :: [(ModuleName, Maybe String)]
- modDecls :: [Decl]
- newtype ModuleName = ModuleName {}
- toModuleName :: [String] -> ModuleName
- getModuleNameList :: ModuleName -> [String]
- data Name
- = Name String
- | QName ModuleName String
- getName :: Name -> String
- data Decl
- getDeclName :: Decl -> Maybe Name
- data Value
- data Type
- data PrimType
- data RefType
- data FunType = Function [Type] Type
- data CompType
Modules
A module is a named container of imports and declarations.
Each module can depend on a set of other modules (translated as include directives). Recursive dependencies are not allowed for now.
Module | |
|
newtype ModuleName Source
A module name is a non-empty list of strings.
toModuleName :: [String] -> ModuleNameSource
getModuleNameList :: ModuleName -> [String]Source
Names
Name of a type, function or constant value.
Note that any Unicode string may be used as a name.
Declarations
An declaration maps a name to type and optionally a value.
getDeclName :: Decl -> Maybe NameSource
A value is anything that can be declared as a C constant.
Types
A type is either an alias, a primitive or a compound type.
A primitive type.
A function type.