ARITY MISMATCH

# Error Code: `ARITY_MISMATCH`

This guide explains why an arity mismatch error may occur and how to fix it.

If you think of relations as tables, the arity of a relation in Rel is the number of columns. For instance, the constants `true` and `false` are relations of arity 0, a single element is a relation of arity 1, and so on. See Relations in Rel Primer: Basic Syntax for more details.

Consider the following example that returns an arity mismatch error:

``````def friends = {("Mike", "Anna"); ("Zoe", "Jenn")}
def zoes_friends = friends("Zoe") ``````

The first relation, `friends`, contains tuples of friends. The second relation, `zoes_friends`, defines Zoe’s friends. The error occurs because:

1. The Rel compiler expects a different number of arguments. The relation `friends("Zoe")` has only one argument, while `friends` is defined by tuples of arity 2.

2. The second relation has parentheses `()` instead of square brackets `[]`. You can think of the operator `()` as a special case of partial relational application used as a boolean filter, with output arity 0 — i.e., `true` or `false`. This means that when you write `friends("Zoe")`, the Rel compiler expects a second argument to check if that tuple is within the relation `friends`. See Arity in Rel Primer: Basic Syntax for more details.

Here’s one way to write the example above correctly:

``````// read query

def friends = {("Mike", "Anna"); ("Zoe", "Jenn")}
def zoes_friends = friends["Zoe"]
def output = zoes_friends``````

This returns Zoe’s friends list.

You can verify the output above:

``````// read query

def friends = {("Mike", "Anna"); ("Zoe", "Jenn")}
def zoes_friends = friends("Zoe", "Jenn")
def output = zoes_friends``````

This returns `()`, i.e., `true`, confirming that the tuple is within the relation `friends`.