简体   繁体   中英

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

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.

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM