Why do we put a 'where' after defining data types in Agda?

80 Views Asked by At

Suppose I wish to define Bool as a type, I would write:

data Bool : Type where

I don't quite understand why I must keep 'where' at the end, what purpose does it play in the Syntax? Why was the above preferred over say:

data Bool : Type

Was this arbitrary or is there some deep logic underlying?

By the way, I am a total noob at programming, so please explain using most simple words.

1

There are 1 best solutions below

0
Jesper On

With the where keyword, we can write the following:

data Bool : Set where true false : Bool

Without the where keyword, this would be

data Bool : Set true false : Bool

but this would be ambiguous: true could be defined to be an element of type Level, in which case this would be defining a datatype at sort Set true with a single constructor false.