Skip to content

Reference to a canonical module in values #45

@rpominov

Description

@rpominov

I propose adding the following section to the specification:


Any value may have a reference to a canonical module that works with values of that value's type. The reference should be in the static-land/canonical property. For example:

const ListModule = {
  of(x) {
    return {'static-land/canonical': ListModule, data: [x]}
  },
  map(f, v) {
    return {'static-land/canonical': ListModule, data: v.data.map(f)}
  }
}

In case a value has a reference to a canonical module, that module must produce values with references to itself. In the following example, list is an incorrect value, because ListModule2 does not produce values with references to itself:

const ListModule2 = {
  of(x) {
    return {data: [x]}
  },
  map(f, v) {
    return {data: v.data.map(f)}
  }
}

const list = {'static-land/canonical': ListModule2, data: [1]}

Note that the ListModule2 here is correct. Only the list value doesn't follow the specification.


This will allow for generic code without passing modules. For example:

function lift2(f, a, b) {
  const T = a['static-land/canonical']
  return T.ap(T.map(a => b => f(a, b), a), b)
}

lift2((x, y) => x + y, ListModule.of(2), ListModule.of(3)) // ListModule.of(5)

Any thoughts on the idea itself, or specific details, or wording of the section?

This idea was discussed before in fantasyland/fantasy-land#199

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions