Types
FTL supports the following types: Int
(64-bit), Float
(64-bit), String
, Bytes
(a byte array), Bool
, Time
,
Any
(a dynamic type), Unit
(similar to "void"), arrays, maps, data structures, and constant enumerations. Each FTL
type is mapped to a corresponding language-specific type. For example in Go Float
is represented as float64
, Time
is represented by time.Time
, and so on.
User-defined types referenced by a verb will be automatically exported as FTL types.
Basic types
The following table shows how FTL types map to language-specific types:
- Go
- Kotlin
- Java
Data structures
FTL supports user-defined data structures, declared using the idiomatic syntax of the target language.
- Go
- Kotlin
- Java
type Person struct {
Name string
Age int
}
data class Person(
val name: String,
val age: Int
)
public class Person {
private final String name;
private final int age;
public Person(String name, int age) {
this.name = name;
this.age = age;
}
}
Generics
FTL has first-class support for generics, declared using the idiomatic syntax of the target language.
- Go
- Kotlin
- Java
type Pair[T, U] struct {
First T
Second U
}
data class Pair<T, U>(
val first: T,
val second: U
)
public class Pair<T, U> {
private final T first;
private final U second;
public Pair(T first, U second) {
this.first = first;
this.second = second;
}
}
Type enums (sum types)
Sum types are supported by FTL's type system.
- Go
- Kotlin
- Java
Sum types aren't directly supported by Go, however they can be approximated with the use of sealed interfaces:
//ftl:enum
type Animal interface { animal() }
type Cat struct {}
func (Cat) animal() {}
type Dog struct {}
func (Dog) animal() {}
Sum types aren't directly supported by Kotlin, however they can be approximated with the use of sealed interfaces:
@Enum
sealed interface Animal
@EnumHolder
class Cat() : Animal
@EnumHolder
class Dog() : Animal
TODO
Value enums
A value enum is an enumerated set of string or integer values.
- Go
- Kotlin
- Java
//ftl:enum
type Colour string
const (
Red Colour = "red"
Green Colour = "green"
Blue Colour = "blue"
)
@Enum
public enum class Colour(
public final val `value`: String,
) {
Red("red"),
Green("green"),
Blue("blue"),
;
}
@Enum
public enum Colour {
Red("red"),
Green("green"),
Blue("blue");
private final String value;
Colour(String value) {
this.value = value;
}
}
Type aliases
A type alias is an alternate name for an existing type. It can be declared like so:
- Go
- Kotlin
- Java
//ftl:typealias
type UserID string
typealias UserID = String
// Java does not support type aliases directly
// Use a wrapper class instead
public class UserID {
private final String value;
public UserID(String value) {
this.value = value;
}
public String getValue() {
return value;
}
}
Type aliases are useful for making code more readable and type-safe by giving meaningful names to types that represent specific concepts in your domain.