Jump to content

Wikifunctions:Type proposals/configuration of functions for given types

From Wikifunctions

Summary

This will perform a similar role to Configuration of functions for given languages (Z14294), but instead of splitting the functions by Natural language (Z60), it will split them by Type (Z4) (likely to switch the function according to its input, output, or both).

Uses

Prompts:

  • Why should this exist?

Some linguistic functions branch naturally according to the dialect. Similarly many functions branch according to the type of input they are given (and/or the output desired).

  • What kinds of functions would be created using this?
    • We will be able to perform object equality (Z13052), but direct the comparisons toward the correct type-specific equality functions.
    • We will be able to appropriately group type-specific versions of the same function with an overarching meta function. For example, we are likely to have a version of n^2 (Z13663) for most other numerical types we enable (integers, reals, complex numbers...).
    • A function written for Gregorian calendar month (Z16098) could easily be generalised to apply to other types of months in other calendar systems.
  • What standard concepts, if any, does this align with?

It is very similar to Configuration of functions for given languages (Z14294), and like it, will need a related type like Function option for a list of languages (Z14293).

Structure

Similar to Configuration of functions for given languages (Z14294). Values would have a list of options. Each option has a function to use for that option and a list of types describing the option to choose. There is also a default function on the main object.

Example values

Example value for multiplication configuration

{
  "type": "configuration of functions for given types",
  "options": [
    "function option of a type",
    {
      "type": "function option of a type",
      "function to use": "multiply two natural numbers",
      "for these types": ["Type", "Natural Number", "Natural Number"]
    },
    {
      "type": "function option of a type",
      "function to use": "multiply signs",
      "for these types": ["Type", "Sign", "Sign"]
    },
    {
      "type": "function option of a type",
      "function to use": "multiply integers",
      "for these types": ["Type", "Integer", "Integer"]
    }
  ],
  "default function": "raise type error"
}
{
  "Z1K1": "Zmmmmm",
  "ZmmmmmK1": [
    "Znnnnn",
    {
      "Z1K1": "Znnnnn",
      "ZnnnnnK1": "Z13539",
      "ZnnnnnK2": ["Z4", "Z13518", "Z13518"]
    },
    {
      "Z1K1": "Znnnnn",
      "ZnnnnnK1": "Z16728",
      "ZnnnnnK2": ["Z4", "Z16659", "Z16659"]
    },
    {
      "Z1K1": "Znnnnn",
      "ZnnnnnK1": "Z17120",
      "ZnnnnnK2": ["Z4", "Z16683", "Z16683"]
    }
  ],
  "ZmmmmmK2": "Zooooo"
}

Validator

The validator ensures that:

  • There are no entries with same list of types as another entry

Identity

Two configuration of functions for given types are the same if they map to the same function for every language (order in the list should not matter).

Converting to code

Python

A dict will be returned to Python code.

JavaScript

An object will be returned to Javascript code.

Renderer

We will use the regular UI for renderering and it will not have a string renderer

Parsers

We will use the regular UI for parsing and it will not have a string parser

Alternatives

Feel free to suggest.

Comments