Haxe is an open source high-level
cross-platform
In computing, cross-platform software (also called multi-platform software, platform-agnostic software, or platform-independent software) is computer software that is designed to work in several computing platforms. Some cross-platform software ...
programming language
A programming language is a system of notation for writing computer programs. Most programming languages are text-based formal languages, but they may also be graphical. They are a kind of computer language.
The description of a programming l ...
and
compiler
In computing, a compiler is a computer program that translates computer code written in one programming language (the ''source'' language) into another language (the ''target'' language). The name "compiler" is primarily used for programs that ...
that can produce applications and source code, for many different
computing platform
A computing platform or digital platform is an environment in which a piece of software is executed. It may be the hardware or the operating system (OS), even a web browser and associated application programming interfaces, or other underlying ...
s from one code-base. It is
free and open-source software
Free and open-source software (FOSS) is a term used to refer to groups of software consisting of both free software and open-source software where anyone is freely licensed to use, copy, study, and change the software in any way, and the source ...
, released under the
MIT License
The MIT License is a permissive free software license originating at the Massachusetts Institute of Technology (MIT) in the late 1980s. As a permissive license, it puts only very limited restriction on reuse and has, therefore, high license co ...
. The compiler, written in
OCaml
OCaml ( , formerly Objective Caml) is a general-purpose, multi-paradigm programming language which extends the Caml dialect of ML with object-oriented features. OCaml was created in 1996 by Xavier Leroy, Jérôme Vouillon, Damien Doligez, D ...
, is released under the
GNU General Public License
The GNU General Public License (GNU GPL or simply GPL) is a series of widely used free software licenses that guarantee end user
In product development, an end user (sometimes end-user) is a person who ultimately uses or is intended to ulti ...
(GPL) version 2.
Haxe includes a set of features and a standard library
[Introduction to the Haxe Standard Library](_blank)
Haxe Docs supported
across all platforms, like
numeric data types,
strings,
array
An array is a systematic arrangement of similar objects, usually in rows and columns.
Things called an array include:
{{TOC right
Music
* In twelve-tone and serial composition, the presentation of simultaneous twelve-tone sets such that the ...
s,
maps
A map is a symbolic depiction emphasizing relationships between elements of some space, such as objects, regions, or themes.
Many maps are static, fixed to paper or some other durable medium, while others are dynamic or interactive. Althoug ...
,
binary
Binary may refer to:
Science and technology Mathematics
* Binary number, a representation of numbers using only two digits (0 and 1)
* Binary function, a function that takes two arguments
* Binary operation, a mathematical operation that ta ...
,
reflection, math,
HTTP
The Hypertext Transfer Protocol (HTTP) is an application layer protocol in the Internet protocol suite model for distributed, collaborative, hypermedia information systems. HTTP is the foundation of data communication for the World Wide Web, ...
, file system and common
file format
A file format is a Computer standard, standard way that information is encoded for storage in a computer file. It specifies how bits are used to encode information in a digital storage medium. File formats may be either proprietary format, pr ...
s. Haxe also includes platform-specific API's for each compiler target.
Kha Kha may refer to:
* Kha (Bengali), a letter
* Kha (Cyrillic), a letter
* Kha (Indic), a consonant
* Ḫāʾ (sometimes khā), Arabic letter خ
* Kha, an ancient Egyptian architect and overseer, in Theban Tomb 8, TT8
Theban Tomb 8, abbreviated T ...
,
OpenFL
OpenFL is a free and open-source software framework and platform for the creation of multi-platform applications and video games. OpenFL applications can be written in Haxe, JavaScript (EcmaScript 5 or 6+), or TypeScript, and may be published as st ...
and
Heaps.io are popular Haxe frameworks that enable creating multi-platform content from one codebase.
Haxe originated
with the idea of supporting
client-side
Client-side refers to operations that are performed by the client in a client–server relationship in a computer network.
General concepts
Typically, a client is a computer application, such as a web browser, that runs on a user's local comp ...
and
server-side
In the client–server model, server-side refers to programs and operations that run on the server. This is in contrast to client-side programs and operations which run on the client.
General concepts
Typically, a server is a computer applicati ...
programming in one language, and simplifying the communication logic between them. Code written in the Haxe language can be
compiled
In computing, a compiler is a computer program that Translator (computing), translates computer code written in one programming language (the ''source'' language) into another language (the ''target'' language). The name "compiler" is primarily ...
into
JavaScript
JavaScript (), often abbreviated as JS, is a programming language that is one of the core technologies of the World Wide Web, alongside HTML and CSS. As of 2022, 98% of Website, websites use JavaScript on the Client (computing), client side ...
,
C++,
Java
Java (; id, Jawa, ; jv, ꦗꦮ; su, ) is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea to the north. With a population of 151.6 million people, Java is the world's mo ...
,
JVM
A Java virtual machine (JVM) is a virtual machine that enables a computer to run Java programs as well as programs written in other languages that are also compiled to Java bytecode. The JVM is detailed by a specification that formally describes ...
,
PHP
PHP is a General-purpose programming language, general-purpose scripting language geared toward web development. It was originally created by Danish-Canadian programmer Rasmus Lerdorf in 1993 and released in 1995. The PHP reference implementati ...
,
C#,
Python,
Lua
Lua or LUA may refer to:
Science and technology
* Lua (programming language)
* Latvia University of Agriculture
* Last universal ancestor, in evolution
Ethnicity and language
* Lua people, of Laos
* Lawa people, of Thailand sometimes referred t ...
and
Node.js
Node.js is an open-source server environment. Node.js is cross-platform and runs on Windows, Linux, Unix, and macOS. Node.js is a back-end JavaScript runtime environment. Node.js runs on the V8 JavaScript Engine and executes JavaScript code ou ...
. Haxe can also directly compile
SWF
SWF ( ) is an Adobe Flash file format used for multimedia, vector graphics and ActionScript.[Open Screen Pr ...](_blank)
,
HashLink
A hash function is any Function (mathematics), function that can be used to map data (computing), data of arbitrary size to fixed-size values. The values returned by a hash function are called ''hash values'', ''hash codes'', ''digests'', or si ...
and
NekoVM
NekoVM is a virtual machine developed by Nicolas Cannasse as part of research and development (R&D) efforts at two independent video game developers in Bordeaux, France: first at Motion Twin and then at Shiro Games. NekoVM's native language is ...
bytecode
Bytecode (also called portable code or p-code) is a form of instruction set designed for efficient execution by a software interpreter. Unlike human-readable source code, bytecodes are compact numeric codes, constants, and references (norma ...
and also runs in interpreted mode.
Haxe supports externs (definition files) that can contain type information of existing libraries to describe target-specific interaction in a type-safe manner, like
C++ header files
Many programming languages and other computer files have a directive, often called include (sometimes copy or import), that causes the contents of the specified file to be inserted into the original file. These included files are called copybooks ...
can describe the structure of existing
object file
An object file is a computer file containing object code, that is, machine code output of an assembler or compiler. The object code is usually relocatable, and not usually directly executable. There are various formats for object files, and the ...
s. This enables to use the values defined in the files as if they were statically typed Haxe entities. Beside externs, other solutions exist to access each platform's native capabilities.
Many popular
IDEs and
source code editor
A source-code editor is a text editor program designed specifically for editing source code of computer programs. It may be a standalone application or it may be built into an integrated development environment (IDE) or web browser. Source-code ed ...
s have
support available for Haxe development. No particular development environment or tool set is officially recommended by the Haxe Foundation, although
VS Code
Visual Studio Code, also commonly referred to as VS Code, is a source-code editor made by Microsoft with the Electron Framework, for Windows, Linux and macOS. Features include support for debugging, syntax highlighting, intelligent code complet ...
,
IntelliJ IDEA
IntelliJ IDEA is an integrated development environment (IDE) written in Java for developing computer software written in Java, Kotlin, Groovy, and other JVM-based languages. It is developed by JetBrains (formerly known as IntelliJ) and is a ...
and HaxeDevelop have most support for Haxe development. The core functionalities of
syntax highlighting
Syntax highlighting is a feature of text editors that are used for programming, scripting, or markup languages, such as HTML. The feature displays text, especially source code, in different colours and fonts according to the category of terms. ...
,
code completion
Autocomplete, or word completion, is a feature in which an application predicts the rest of a word a user is typing. In Android and iOS smartphones, this is called predictive text. In graphical user interfaces, users can typically press the tab ...
,
refactoring
In computer programming and software design, code refactoring is the process of restructuring existing computer code—changing the '' factoring''—without changing its external behavior. Refactoring is intended to improve the design, structu ...
,
debugging
In computer programming and software development, debugging is the process of finding and resolving ''bugs'' (defects or problems that prevent correct operation) within computer programs, software, or systems.
Debugging tactics can involve in ...
, etc. are available to various degrees.
History
Development of Haxe began in October 2005. The first
alpha version
A software release life cycle is the sum of the stages of development and maturity for a piece of computer software ranging from its initial development to its eventual release, and including updated versions of the released version to help impro ...
was released on November 14, 2005.
Haxe 1.0 was released in April 2006, with support for
Adobe Flash
Adobe Flash (formerly Macromedia Flash and FutureSplash) is a multimedia software platform used for production of animations, rich web applications, desktop applications, mobile apps, mobile games, and embedded web browser video players. Fla ...
,
JavaScript
JavaScript (), often abbreviated as JS, is a programming language that is one of the core technologies of the World Wide Web, alongside HTML and CSS. As of 2022, 98% of Website, websites use JavaScript on the Client (computing), client side ...
, and
NekoVM
NekoVM is a virtual machine developed by Nicolas Cannasse as part of research and development (R&D) efforts at two independent video game developers in Bordeaux, France: first at Motion Twin and then at Shiro Games. NekoVM's native language is ...
programs. Support for PHP was added in 2008, and C++ was added in 2009. More platforms such as C# and Java were added with a compiler overhaul in 2012.
Haxe was developed by Nicolas Cannasse and other contributors, and was originally named ''haXe''
because it was short, simple, and "has an X inside", which the author asserts humorously is needed to make any new technology a success.
Haxe is the successor to the open-source
ActionScript
ActionScript is an object-oriented programming language originally developed by Macromedia Inc. (later acquired by Adobe). It is influenced by HyperTalk, the scripting language for HyperCard. It is now an implementation of ECMAScript (meani ...
2 compiler
MTASC
MTASC (Motion-Twin ActionScript 2 Compiler) is an ActionScript 2.0 compiler written in the OCaml programming language by the company Motion Twin. It is free software and can be used alone or with other tools like swfmill to produce SWF
...
,
[MTASC Compiler](_blank)
MTASC website also built by Nicolas Cannasse and is released under the
GNU General Public License
The GNU General Public License (GNU GPL or simply GPL) is a series of widely used free software licenses that guarantee end user
In product development, an end user (sometimes end-user) is a person who ultimately uses or is intended to ulti ...
version 2 or later.
Compiler
The Haxe language can compile into
bytecode
Bytecode (also called portable code or p-code) is a form of instruction set designed for efficient execution by a software interpreter. Unlike human-readable source code, bytecodes are compact numeric codes, constants, and references (norma ...
that can be executed directly by the
virtual machine
In computing, a virtual machine (VM) is the virtualization/ emulation of a computer system. Virtual machines are based on computer architectures and provide functionality of a physical computer. Their implementations may involve specialized har ...
s it targets. It can compile to
source code
In computing, source code, or simply code, is any collection of code, with or without comment (computer programming), comments, written using a human-readable programming language, usually as plain text. The source code of a Computer program, p ...
in
C++,
JavaScript
JavaScript (), often abbreviated as JS, is a programming language that is one of the core technologies of the World Wide Web, alongside HTML and CSS. As of 2022, 98% of Website, websites use JavaScript on the Client (computing), client side ...
,
PHP
PHP is a General-purpose programming language, general-purpose scripting language geared toward web development. It was originally created by Danish-Canadian programmer Rasmus Lerdorf in 1993 and released in 1995. The PHP reference implementati ...
,
C#,
Java
Java (; id, Jawa, ; jv, ꦗꦮ; su, ) is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea to the north. With a population of 151.6 million people, Java is the world's mo ...
,
Python and
Lua
Lua or LUA may refer to:
Science and technology
* Lua (programming language)
* Latvia University of Agriculture
* Last universal ancestor, in evolution
Ethnicity and language
* Lua people, of Laos
* Lawa people, of Thailand sometimes referred t ...
. Haxe also has an interpreter called ''eval''. This same interpreter is also used compile-time to run macros, which allow modification of the
AST.
This strategy of compiling to multiple source code languages is inspired by the
write once, run anywhere
Write once, run anywhere (WORA), or sometimes Write once, run everywhere (WORE), was a 1995 slogan created by Sun Microsystems to illustrate the cross-platform benefits of the Java language. Ideally, this meant that a Java program could be develop ...
paradigm. It also allows the programmer to choose the best platform for the job. Typical Haxe programs run identically on all platforms, but developers can specify platform-specific code and use
conditional compilation
In computer programming, conditional compilation is a compilation technique which results in an executable program that is able to be altered by changing specified parameters. This technique is commonly used when these alterations to the program ...
to prevent it from compiling on other platforms.
The Haxe compiler is an
optimizing compiler
In computing, an optimizing compiler is a compiler that tries to minimize or maximize some attributes of an executable computer program. Common requirements are to minimize a program's execution time, memory footprint, storage size, and power cons ...
, and uses
field and function inlining,
tail recursion elimination
In computer science, a tail call is a subroutine call performed as the final action of a procedure. If the target of a tail is the same subroutine, the subroutine is said to be tail recursive, which is a special case of direct recursion. Tail recur ...
,
constant folding,
loop unrolling
Loop unrolling, also known as loop unwinding, is a loop transformation technique that attempts to optimize a program's execution speed at the expense of its binary size, which is an approach known as space–time tradeoff. The transformation ...
and
dead code elimination
In compiler theory, dead-code elimination (also known as DCE, dead-code removal, dead-code stripping, or dead-code strip) is a compiler optimization to remove code which does not affect the program results. Removing such code has several benefits: ...
(DCE) to optimize the run-time performance of compiled programs. The Haxe compiler offers opt-in
null-safety, it checks compile-time for nullable values.
Targets
In Haxe, supported platforms are known as "targets", which consist of the following modules:
* The compiler-backends that are responsible for generating the respective code.
* The run-time specific APIs that go beyond the core language support (platform-targets).
The following table documents platform and language support in Haxe. The Haxe language allows developers to gain access to many platform features, but Haxe is not a full featured engine, they might need frameworks that enable create content for certain platforms.
Advantages of Haxe
* Ability to target multiple platforms and devices using the same language
* Ability to use strictly-typed code
* Ability to use macros (syntax transformation) which can be done with Haxe language
* Added language features such as
extension methods
In object-oriented computer programming, an extension method is a method added to an object after the original object was compiled. The modified object is often a class, a prototype or a type. Extension methods are features of some object-ori ...
and
functional programming
In computer science, functional programming is a programming paradigm where programs are constructed by applying and composing functions. It is a declarative programming paradigm in which function definitions are trees of expressions that ...
* The run-time performance of Haxe programs is at comparable speed to handwritten sources.
Language
Haxe is a general-purpose language supporting
object-oriented programming
Object-oriented programming (OOP) is a programming paradigm based on the concept of " objects", which can contain data and code. The data is in the form of fields (often known as attributes or ''properties''), and the code is in the form of ...
,
generic programming
Generic programming is a style of computer programming in which algorithms are written in terms of types ''to-be-specified-later'' that are then ''instantiated'' when needed for specific types provided as parameters. This approach, pioneered b ...
, and various
functional programming
In computer science, functional programming is a programming paradigm where programs are constructed by applying and composing functions. It is a declarative programming paradigm in which function definitions are trees of expressions that ...
constructs. Features such as
iteration
Iteration is the repetition of a process in order to generate a (possibly unbounded) sequence of outcomes. Each repetition of the process is a single iteration, and the outcome of each iteration is then the starting point of the next iteration. ...
s,
exceptions, and
code reflection are also built-in functions of the language and libraries. Unusual among programming languages, Haxe contains a type system which is both
strong and
dynamic
Dynamics (from Greek δυναμικός ''dynamikos'' "powerful", from δύναμις ''dynamis'' " power") or dynamic may refer to:
Physics and engineering
* Dynamics (mechanics)
** Aerodynamics, the study of the motion of air
** Analytical dyna ...
. The compiler will check types implicitly using
type inferencing and give compile-time errors, but it also enables the programmer to bypass type-checking and rely on the target platform's dynamic type-handling. All of the native target APIs can be used.
Type system
Haxe has a sophisticated and flexible type system. The type kinds it offers are classes, interfaces, function-method types, anonymous types,
algebraic data type
In computer programming, especially functional programming and type theory, an algebraic data type (ADT) is a kind of composite type, i.e., a type formed by combining other types.
Two common classes of algebraic types are product types (i.e., ...
s (called ''enum'' in Haxe), and abstract types.
Parametric polymorphism
In programming languages and type theory, parametric polymorphism allows a single piece of code to be given a "generic" type, using variables in place of actual types, and then instantiated with particular types as needed. Parametrically polymorph ...
is possible with classes, algebraic types and function types, giving the language support for
generic programming
Generic programming is a style of computer programming in which algorithms are written in terms of types ''to-be-specified-later'' that are then ''instantiated'' when needed for specific types provided as parameters. This approach, pioneered b ...
based on type erasure. This includes support for
variance
In probability theory and statistics, variance is the expectation of the squared deviation of a random variable from its population mean or sample mean. Variance is a measure of dispersion, meaning it is a measure of how far a set of number ...
in
polymorphic function
In programming language theory and type theory, polymorphism is the provision of a single interface to entities of different types or the use of a single symbol to represent multiple different types.: "Polymorphic types are types whose operation ...
s, although not in
type constructor
In the area of mathematical logic and computer science known as type theory, a type constructor is a feature of a typed formal language that builds new types from old ones. Basic types are considered to be built using nullary type constructors. So ...
s.
The
type system
In computer programming, a type system is a logical system comprising a set of rules that assigns a property called a type to every "term" (a word, phrase, or other set of symbols). Usually the terms are various constructs of a computer progra ...
is
static
Static may refer to:
Places
*Static Nunatak, a nunatak in Antarctica
United States
* Static, Kentucky and Tennessee
*Static Peak, a mountain in Wyoming
** Static Peak Divide, a mountain pass near the peak
Science and technology Physics
*Static e ...
unless annotations for
dynamic typing
In computer programming, a type system is a logical system comprising a set of rules that assigns a property called a type to every "term" (a word, phrase, or other set of symbols). Usually the terms are various constructs of a computer progra ...
are present, for use with targets that support them.
Type checking
In computer programming, a type system is a logical system comprising a set of rules that assigns a property called a type to every "term" (a word, phrase, or other set of symbols). Usually the terms are various constructs of a computer program ...
follows
nominal typing with the exception of
anonymous type Anonymous types are a feature of C# 3.0, Visual Basic .NET 9.0, Oxygene, Scala and Go that allows data types to encapsulate a set of properties into a single object without having to first explicitly define a type. This is an important feature ...
s where
structural typing
A structural type system (or property-based type system) is a major class of type systems in which type compatibility and equivalence are determined by the type's actual structure or definition and not by other characteristics such as its name o ...
is used instead. Finally,
type inference
Type inference refers to the automatic detection of the type of an expression in a formal language. These include programming languages and mathematical type systems, but also natural languages in some branches of computer science and linguistics. ...
is supported, allowing for variable declarations without
type annotation
In computer science, a type signature or type annotation defines the inputs and outputs for a function, subroutine or method. A type signature includes the number, types, and order of the arguments contained by a function. A type signature is typ ...
s.
Modules and namespaces
All Haxe code is organized in modules, which are addressed using paths. In essence, each ''.hx'' file represents a module which may contain several types. For example, to create the type
A
in the package ''my.pack'' as shown, the folder structure should be ''my\pack'' and the file could be ''A.hx'' in the folder ''pack''.
// file my/pack/A.hx
package my.pack;
class A
In other modules, other types can be imported by putting
import
statements below the package definition, e.g.
import my.pack.A;
A module can contain multiple types, such as the following. It is possible to import one type at a time from that module, using
import my.pack2.A;
. A type may be
private
, in which case only its containing module can access it.
package my.pack2;
typedef A =
private typedef B =
Classes
Classes (keyword
class
) in Haxe are similar to those in Java or TypeScript. Their fields can be either methods, variables, or properties, each static or per instance respectively. Haxe supports the accessors
public
and
private
, and more advanced methods for access control that are denoted using annotations. Methods and static constant variables can be inlined using the keyword
inline
. Fields can be marked as
final
to declare a constant that must be initialized immediately or in the constructor and cannot be written to, in case of function
final
will mark as non-overridable in subclasses.
Interfaces in Haxe are very similar to those in, for example, Java.
interface ICreature
class Fly implements ICreature
Generics
Haxe supports
generic programming
Generic programming is a style of computer programming in which algorithms are written in terms of types ''to-be-specified-later'' that are then ''instantiated'' when needed for specific types provided as parameters. This approach, pioneered b ...
. The following is an example of the
identity function
Graph of the identity function on the real numbers
In mathematics, an identity function, also called an identity relation, identity map or identity transformation, is a function that always returns the value that was used as its argument, unc ...
.
function identity(arg:T):T
Enumerated types
Enumerated type
In computer programming, an enumerated type (also called enumeration, enum, or factor in the R programming language, and a categorical variable in statistics) is a data type consisting of a set of named values called ''elements'', ''members'', ' ...
s are an important feature of the language; they can have type parameters and be recursive.
They provide basic support for
algebraic data type
In computer programming, especially functional programming and type theory, an algebraic data type (ADT) is a kind of composite type, i.e., a type formed by combining other types.
Two common classes of algebraic types are product types (i.e., ...
s, allowing the inclusion of
product type
In programming languages and type theory, a product of ''types'' is another, compounded, type in a structure. The "operands" of the product are types, and the structure of a product type is determined by the fixed order of the operands in the produ ...
s, in a fashion similar to
Haskell
Haskell () is a general-purpose, statically-typed, purely functional programming language with type inference and lazy evaluation. Designed for teaching, research and industrial applications, Haskell has pioneered a number of programming lan ...
and
ML. A
switch
expression can apply
pattern matching
In computer science, pattern matching is the act of checking a given sequence of tokens for the presence of the constituents of some pattern. In contrast to pattern recognition, the match usually has to be exact: "either it will or will not be ...
to an enum value, allowing for elegant solutions to complex programming problems:
enum Color
class Colors
Examples of parametric enum types are the Haxe standard library types Option and Either:
enum Option
enum Either
Haxe also supports
generalized algebraic data type In functional programming, a generalized algebraic data type (GADT, also first-class phantom type, guarded recursive datatype, or equality-qualified type) is a generalization of parametric algebraic data types.
Overview
In a GADT, the product co ...
s (GADTs).
Anonymous types
Anonymous types are defined by denoting their structure explicitly, using a syntax that follows the mathematical record-based representation of a type. They can be used to implement structural typing for function arguments (see below), and can be given an alias with the keyword
typedef
:
typedef AliasForAnon = ;
Function types
Functions are first-class values in Haxe. Their type is denoted by using arrows between argument types, and between the argument type(s) and return type, as common in many functional languages. However, unlike in prominent examples like
Haskell
Haskell () is a general-purpose, statically-typed, purely functional programming language with type inference and lazy evaluation. Designed for teaching, research and industrial applications, Haskell has pioneered a number of programming lan ...
or the
ML language family, not all functions are unary functions (functions with one argument only), and in Haxe, functions can't be
partially applied per default. Thus, the following type signatures have different semantics than in the aforementioned languages. The type
F1
is a function that takes a
String
as arguments and returns a value of type
Float
.
Types
F1
and
F2
denote the same type, except that
F2
uses labelled parameter, which is useful for completion and documentation purposes.
Types
F4
and
F5
denote the same type. Both are binary functions that return a binary function of type
F3
. For
F5
the syntax to declare a function type within a function type is used.
typedef F1 = String -> Float;
typedef F2 = (text:String) -> Float;
typedef F3 = (score:Int, text:String) -> Float;
typedef F4 = (score:Int, text:String) -> F3;
typedef F5 = (score:Int, text:String) -> ((score:Int, text:String) -> Float);
Abstract types
The latest addition to the Haxe type system is a concept termed ''abstract types''. As used in Haxe, this refers to something different from a conventional
abstract type
In programming languages, an abstract type is a type in a nominative type system that cannot be instantiated directly; a type that is not abstract – which ''can'' be instantiated – is called a ''concrete type''. Every instance of an abstra ...
. They are used to make conversions between types implicit, allowing reuse of existing types for specific purposes, like implementing types for units of measurement. This greatly reduces the risk of mixing up values of the same underlying type, but with different meanings (e.g., miles vs. km).
The following example assumes that the metric system is the default, while a conversion to miles is needed for legacy data. Haxe can automatically convert miles to kilometers, but not the reverse.
abstract Kilometer(Float)
abstract Mile(Float)
class Test
As the example shows, no explicit conversion is needed for the assignment "km = one100Miles;" to do the right thing.
Structural typing
In many functional programming languages,
structural typing
A structural type system (or property-based type system) is a major class of type systems in which type compatibility and equivalence are determined by the type's actual structure or definition and not by other characteristics such as its name o ...
plays a major role. Haxe employs it in the presence of anonymous types, using the
nominative typing of
object-oriented programming
Object-oriented programming (OOP) is a programming paradigm based on the concept of " objects", which can contain data and code. The data is in the form of fields (often known as attributes or ''properties''), and the code is in the form of ...
, when only named types are involved. Anonymous types in Haxe are analogous to the implicit interfaces of the language
Go as to typing. In contrast with Go interfaces, it is possible to construct a value using an anonymous type.
class FooBar
Internal architecture
The Haxe compiler is divided into one frontend and multiple backends. The frontend creates an
abstract syntax tree
In computer science, an abstract syntax tree (AST), or just syntax tree, is a tree representation of the abstract syntactic structure of text (often source code) written in a formal language. Each node of the tree denotes a construct occurring ...
(AST) from the source code, and performs type checking,
macro expansion
In computer programming, a macro (short for "macro instruction"; ) is a rule or pattern that specifies how a certain input should be mapped to a replacement output. Applying a macro to an input is known as macro expansion. The input and outp ...
, and optimization on the
AST. The various backends
translate
Translation is the communication of the meaning of a source-language text by means of an equivalent target-language text. The English language draws a terminological distinction (which does not exist in every language) between ''transla ...
the processed AST into source code or generate
bytecode
Bytecode (also called portable code or p-code) is a form of instruction set designed for efficient execution by a software interpreter. Unlike human-readable source code, bytecodes are compact numeric codes, constants, and references (norma ...
, depending on their target.
The compiler is written in
OCaml
OCaml ( , formerly Objective Caml) is a general-purpose, multi-paradigm programming language which extends the Caml dialect of ML with object-oriented features. OCaml was created in 1996 by Xavier Leroy, Jérôme Vouillon, Damien Doligez, D ...
. It can be run in server-mode to provide code completion for
integrated development environment
An integrated development environment (IDE) is a software application that provides comprehensive facilities to computer programmers for software development. An IDE normally consists of at least a source code editor, build automation tools a ...
s (IDEs) and maintain a cache, to further speed compiling.
[Server mode command-line: ]haxe --wait ost:ort
See also
*
Comparison of IDE choices for Haxe programmers
*
Dart (programming language)
Dart is a programming language designed for client development, such as for the web and mobile apps. It is developed by Google and can also be used to build server and desktop applications.
It is an object-oriented, class-based, garbage-col ...
*
Nim (programming language)
Nim is a general-purpose, multi-paradigm, statically typed, compiled systems programming language, designed and developed by a team around Andreas Rumpf. Nim is designed to be "efficient, expressive, and elegant", supporting metaprogramming, ...
*
Opa (programming language)
Opa is an open-source programming language for developing scalable web applications.
It can be used for both client-side and server-side scripting, where complete programs are written in Opa and subsequently compiled to Node.js on the server a ...
*
Clojure
Clojure (, like ''closure'') is a dynamic and functional dialect of the Lisp programming language on the Java platform. Like other Lisp dialects, Clojure treats code as data and has a Lisp macro system. The current development process is ...
*
CoffeeScript
CoffeeScript is a programming language that compiles to JavaScript. It adds syntactic sugar inspired by Ruby, Python, and Haskell in an effort to enhance JavaScript's brevity and readability. Specific additional features include list comprehen ...
*
TypeScript
TypeScript is a free and open source programming language developed and maintained by Microsoft. It is a strict syntactical superset of JavaScript and adds optional static typing to the language. It is designed for the development of large appl ...
*
Scala (programming language)
*
Vala (programming language)
Vala is an object-oriented programming language with a self-hosting compiler that generates C code and uses the GObject system.
Vala is syntactically similar to C# and includes notable features such as anonymous functions, signals, proper ...
*
Emscripten
Emscripten is an LLVM/Clang-based compiler that compiles C and C++ source code to WebAssembly (or to a subset of JavaScript known as asm.js, its original compilation target before the advent of WebAssembly in 2017), primarily for execution in ...
*
OpenFL
OpenFL is a free and open-source software framework and platform for the creation of multi-platform applications and video games. OpenFL applications can be written in Haxe, JavaScript (EcmaScript 5 or 6+), or TypeScript, and may be published as st ...
References
External links
*
{{JavaScript
Programming languages
Object-based programming languages
Functional languages
Multi-paradigm programming languages
OCaml software
Programming languages created in 2005
Software using the GPL license
Source-to-source compilers
Pattern matching programming languages
Statically typed programming languages