This is part of a series of examples of the Amulet programming language. If you do not yet have an Amulet compiler, please refer to the installation instructions.
open import "foo.ml" imports
foo from the library path.
Let bindings introduce variables. These variables can not be mutated.
Type inference can figure out the type of a variable without the programmer having to supply it.
(+) operates on ints,
(+.) on floats.
type construct can be used to define a new data type. Types are defined by listing their constructors
Values of algebraic data types can be taken apart with pattern matching.
function keyword abbreviates a pattern matching function.
Pattern matching on
bool can be done with
if .. then .. else ...
User-defined data types can be recursive.
Recursive functions need a
rec keyword, as in OCaml.
Concatenation is done using the
Types can have parameters. These stand for another type, and can be inferred.
Amulet has a built-in type of lists,
Lists can be manipulated using list comprehensions.
List literal syntax can also be used in patterns.
Type classes are used for principled overloading.
Methods can be used with any type that has a corresponding
Type class methods can be polymorphic in their return types.
into_box is parametrised by a type constructor.
Amulet selects the instance to use automatically, based on the context
into is used in.
into_box is almost the standard class
applicative. Amulet has special syntax for using
applicative functors, idiom brackets:
Idiom brackets desugar into uses of
<*>. These definitions of
cartesian are identical.
Amulet has special syntax for use of the
monad option instance aborts the computation when it encounters a
None are simply chained.