What basic types does EK9 have?
← Getting Started · Ref: Q23
EK9 has a rich set of built-in types organized into several categories.
PRIMITIVES
String Text values: "Hello" Integer Whole numbers: 42 Float Decimal numbers: 3.14 Boolean true or false Character Single character: 'A' Bits Bit manipulation Void No value (used in type signatures)
RICH VALUE TYPES
These go far beyond what most languages provide as built-ins:
Date, Time, DateTime Calendar and clock values Duration, Millisecond Time spans Money Currency-aware: 9.99#USD, 100#GBP Colour Colour values: #FF8800 Dimension Physical measurements: 100cm, 5.2kg Resolution Display resolution Regex Regular expressions GUID Globally unique identifiers HMAC Cryptographic message authentication Version Semantic version numbers Path Geometric paths Locale Internationalization locale JSON JSON data handling
GENERIC COLLECTION TYPES
Parameterized with 'of' syntax:
List of T Ordered collection: List() of String Dict of (K, V) Key-value mapping: Dict() of (String, Integer) DictEntry of (K, V) Single key-value pair Optional of T Value that may be absent Result of (O, E) Success or error outcome Iterator of T Lazy sequence traversal PriorityQueue of T Priority-ordered queue MutexLock of T Thread-safe wrapper
GENERIC FUNCTION TYPES (Key Building Block)
Unlike Java where functional types were an afterthought (java.util.function added in Java 8), EK9 builds these into the language as first-class constructs. There are 16 generic function types: 8 pure and 8 non-pure.
Pure function types (no side effects):
Function of (T, R) Takes T, returns R Consumer of T Takes T, no return Supplier of T No input, returns T Predicate of T Takes T, returns Boolean UnaryOperator of T Takes T, returns T (same type) BiFunction of (T, U, R) Takes T and U, returns R BiConsumer of (T, U) Takes T and U, no return BiPredicate of (T, U) Takes T and U, returns Boolean Comparator of T Compares two T values, returns Integer
Non-pure function types (can have side effects, mutate state, perform I/O):
Routine of (T, R) Takes T, returns R Acceptor of T Takes T, no return Producer of T No input, returns T Assessor of T Takes T, returns Boolean BiRoutine of (T, U, R) Takes T and U, returns R BiAcceptor of (T, U) Takes T and U, no return BiAssessor of (T, U) Takes T and U, returns Boolean
The pure/non-pure split is a language-level design decision. Pure functions are guaranteed safe for caching, parallelism, and testing. Non-pure functions are for I/O, state mutation, and real-world interaction. The compiler enforces this distinction.
I/O TYPES
Stdout, Stderr, Stdin Console I/O TextFile File reading and writing FileSystem File system operations FileSystemPath File and directory paths
NETWORK TYPES
TCP TCP socket communication UDP UDP datagram communication
SYSTEM TYPES
OS Operating system information
EnvVars Environment variable access
Signals OS signal handling
SystemClock System time source
GetOpt Command-line option parsing
SECURITY TYPES
InputSanitizer XSS, SQL injection, command injection protection Exception Error handling with exit codes
All generic types use the 'of' keyword for parameterization: List of String, Dict of (String, Integer), Function of (Integer, String). Built-in generic types are closed and cannot be extended. Use composition and delegation instead of inheritance.
Use 'ek9 -h TypeName' to see the full API for any built-in type, including constructors, methods, and operators. For example: 'ek9 -h String', 'ek9 -h List', 'ek9 -h Function'. Use 'ek9 -H' to list all available help topics. See also Q21 (How do I get help on a specific EK9 type or keyword?) for full details on the help system. See Q54 for the pure/non-pure distinction between Consumer and Acceptor, and the complete set of built-in abstract function types. See Q99 for creating enumerations. See Q140 for declaring built-in types as constants. See Q24 for type conversion. See Q26 for no primitives.
Example
defines module qa.basic.types defines class CheckExtension extends Check Check as open default Check() override operator ? as pure <- rtn <- true defines function doubleIt() as pure -> operand as Integer <- result as Integer: operand * 2 defines program BasicTypes() stdout <- Stdout() // Primitives greeting <- "Hello" count <- 42 ratio <- 3.14 isReady <- true letter <- 'A' // Rich value types today <- Date() amount <- 9.99#USD shade <- #FF8800 width <- 100cm // Generic collection names <- List() of String names += "Alice" names += "Bob" // Generic function type - pure transformation transform <- doubleIt stdout.println(`${greeting} ${count} ${ratio}`) stdout.println(`Ready: ${isReady} Letter: ${letter}`) stdout.println(`Amount: ${amount}`) stdout.println(`Colour: ${shade}`) stdout.println(`Width: ${width}`) stdout.println(`Today: ${today}`) stdout.println(`Names: ${names}`) stdout.println(`Doubled: ${transform(21)}`) // Predicate - pure boolean test (built-in param names: t, r) isPositive <- (threshold: 0) is Predicate of Integer as pure function r :=? t > threshold if isPositive(count) stdout.println(`${count} is positive`)
Common mistakes
E05030 — Built-in generic types like List, Dict, and Optional are closed and cannot be extended. Use composition and delegation instead of inheritance. See ek9 -h E05030 for details.
Incorrect:
CheckExtension extends List of String
Correct:
CheckExtension extends Check
E50010 — A typo in the type name 'Listt' means the compiler cannot find any type with that name. EK9 type names are case-sensitive and must be spelled exactly. See ek9 -h E50010 for details.
Incorrect:
names <- Listt() of String
Correct:
names <- List() of String
Other ways to ask this
- What types are built into EK9?
- What generic types does EK9 provide?
- Does EK9 have functional types like Function or Predicate?
- What collection types does EK9 have?
Coming from another language?
Java: primitives + Object wrappers + java.util collections + java.util.function (added Java 8), Python: built-in types + typing module, Rust: primitives + std collections + Fn/FnMut/FnOnce traits, Go: primitives + slices + maps + func types. EK9: all types built-in with consistent operators. Unique: Money, Colour, Dimension as primitives. 16 generic function types with enforced pure/non-pure split. No afterthought functional types.
Keywords: types, intro, type, beginner, first, available, built-in, all, categories, primitive, what, overview, migrate, start