Skip to main content

Type Philosophy

Hamelin is a typed language, which prevents query mistakes, provides better error messages, and simplifies translation definitions.

Design Philosophy

You mostly won't think about types when writing queries. You'll learn about them when something doesn't type check and Hamelin gives you a clear error message. Hamelin catches type errors before they reach the SQL engine, so you get helpful feedback about your Hamelin code instead of confusing messages about generated SQL.

Umbrella Types

Hamelin groups related types under umbrella categories instead of exposing every SQL type variation. As an example, all integer types from tinyint to bigint become the single integer type for type checking. You can reason about your code more easily while still getting precise error messages.

Error Prevention

Types catch mistakes early and give you clear feedback. When something doesn't type check, errors point to your Hamelin code, not to generated SQL that would confuse you.

Transparent Mapping

Hamelin types map cleanly to SQL types without requiring you to think about storage details. The system handles these details automatically while preserving the semantic meaning of your data.

Function Overloading

Hamelin's type system allows it to use the same function name for operations on different types. You write sum() whether you're aggregating a field or adding up an array - no need for separate sum_numbers() and array_sum() functions. This makes it easier on the author. It also makes it possible for Hamelin's implementation to define dialect-specific translations.

Type Inference

Hamelin figures out types from your expressions and data automatically. You don't need to declare types. Hamelin determines them based on how you use values in operations and functions.

For example:

  • 42 + 3.14 results in a double (floating-point arithmetic)
  • 'hello' + 'world' results in a string (string concatenation)
  • timestamp > '2024-01-01' results in a boolean (comparison operation)
  • sum(revenue) works as an aggregation function in AGG commands
  • sum([1, 2, 3]) works on arrays and returns 6

Type inference also powers Hamelin's function translation, ensuring that operations translate to the right SQL functions based on the inferred types of their arguments. This lets you focus on expressing your logic clearly while the type system works behind the scenes to ensure correctness and give you helpful feedback when things go wrong.