ipld / specs

Content-addressed, authenticated, immutable data structures
Other
592 stars 108 forks source link

schema prelude needs documentation #301

Open warpfork opened 3 years ago

warpfork commented 3 years ago

IPLD Schemas contain a couple of type definitions that are so useful that we don't want to repeat them in each schema. These are declared in something called the "prelude", and can be thought of as implicitly present in the top of every schema.

This set of type definitions is essentially setting a type name for each of the kinds, and creating a concept of Any.

The prelude is this:

type Bool bool
type Int int
type Float float
type String string
type Bytes bytes
type Map {String : nullable Any}
type List [nullable Any]
type Link link
type Any union {
    | Bool   bool
    | Int    int
    | Float  float
    | String string
    | Bytes  bytes
    | Map    map
    | List   list
    | Link   link
} representation kinded

This has (at least) two purposes:

We should have this documentation in general (and can probably largely copy-paste the above into the docs, I suppose), but also there's a couple more things to consider when we put it into pages:

  1. We probably want to associate some recommendations to library authors about how to implement this prelude stuff?
  2. We might need a whole section devoted to Any, and possibly its applications (for example: lots of ADLs that are some kind of container type have an Any field somewhere where they store their contained values). We'll almost certainly need to link to it from other docs pages.
warpfork commented 3 years ago

I did indeed find the need to write a separate issue to fully tackle the situation with Any. It's turned out the it's-just-a-kinded-union definition has some implications that (though they might be logically consistent) aren't very user-friendly. The issue for this is https://github.com/ipld/specs/issues/318 .