AML Types
Introduction
AML includes a powerful type system that enables both a real-time feedback to analysts to help them avoid errors early, and as the basis for sophisticated reusability features such as constant declaration, functions, and extend.
Basic types
Number
- All kind of numbers (including integer and fractional)
Number pi = 3.14159265
Number b = 2
Number c = -10
Int
- Represents numbers without decimal
Int a = 1
Int b = 2
Int c = -100
Boolean
Boolean is_truthy = true
Boolean is_falsy = false
String
A string is a sequence of characters used to represent text.
AML supports 2 kind of strings:
- normal string (single/double quotes)
- multi-line string (triple quotes)
const model_name = 'ecommerce.users' // single-quote
const dataset_name = "ecommerce" // double-quote
// Multi-line string
const note = '''
This is
a note
that expands
on multiple
lines
'''
// "This is\na note\nthat expands\non multiple\nlines"
List
- Stores a collection of elements, typically of the same type
- Syntax:
List[T](whereTis element’s type)
Type ListInt = List[Int]
Type ListString = List[String]
ListInt numbers = [1, 2, 3]
ListString names = ['Alex', 'John', 'Bob']
// access elements inside a list
numbers(0) // 1
numbers(1) // 2
numbers(2) // 3
names(1) // 'John'
Dictionary
- Stores a collection of key-value pairs
- Each key-value pair maps the key to its associated value
- Syntax:
Dict[K, V]whereKis a key’s type,Vis a value’s type
Type NumberDict = Dict[String, Number]
NumberDict employee_ages = {
alex: 23
bob: 30
john: 29
}
Type StringDict = Dict[String, String]
StringDict employee_addresses = {
alex: '505 SW 1st Ave'
john: ' 4070 Red Arrow Hwy'
bob: '851 St Georges Ave'
}
// access dictionary entries
employee_ages('alex') // 23
employee_addresses('bob') // '851 St Georges Ave'
Any
- is a type that can hold any value, effectively opting out of type checking
Custom types
You can also define your own types to group related values under one name, for example settings that you pass to a function:
Type KpiSettings {
title: String
format (default: '#,###'): String
}
See AML Custom Types for the full guide.