-
-
Notifications
You must be signed in to change notification settings - Fork 235
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mathematical reasoning of API design #736
Comments
Associated functionsAn extension for something I call "associated functions": Examples:
A associated functions can be used to prove things about compositions or test for combination errors. It seems repeated associated functions are communative and can be written Very often you have to figure out the values and it is possible to make mistakes, but once you have written down something it becomes easier to puzzle the picture together. Symmetry rule
SemanticsThe earlier idea that we built on is that all functions are objects and all objects are functions. With associated functions you can make a new analogy: All functions or objects are paths through a space.
Earlier the semantics of |
Sets and values of typesA set is an object which contains other objects where each object occur exactly once. For example, if
When reasoning about types, there is no need to distinguish between types and values because every value can be a set and therefore values can emulate types and types can emulate values. It is only when writing the Rust code you have to choose whether to interpret something as a value or a type. For example:
A set has an associated function
You can choose to omit The relationship between types and values and the idea of sets can be derived from a kind of asymmetry that appears to be symmetric:
It is possible to express all properties of everything without adding specific notations, but some ideas are nice to express in shorter form because they are more useful. |
niconii made an interesting twist http://puu.sh/hda0w/d54b90ff5a.txt |
GenericsGenerics can be thought of a function that returns a set:
|
Temporal logicThe syntax can be extended using a parameter of time Example:
Temporal constraints can help solving problems by finding an algorithm which reaches a state where the constraints no longer changes. When parts of the constraints no longer changes conditioned on some acquired knowledge, this knowledge can then be computed to reduce the problem. |
In Rust you can use mathematics to help reason about API design. In code, there is no distinction between
self
as a function, as a variable or as a parameter to its method. By translation into mathematical functions, it might become easier to discover issues. It can also be used to transform the API into another equivalent form and play around with the concepts.For example, in mathematics the function
f(t)
usually means a function of time. It does not tell whatf
is or how you computef
, but it is clear thatf
means something more specific thant
. It would be awkward to writet(f)
because we think of time as something generic and independent. Neither it does tell whatf(t)
returns, but if it returned an image, we could writef(t) -> img
.Pure functions in the mathematical sense can be used to reason about dependencies. When you have
f(x)
andg(f)
, theng
does not depend onx
. Example:animation(time) -> image
andframes(animation) -> uint
.frames
is independent oftime
.When you write
g(f(t))
you can also writeg(f, t)
which means you also can couple and decouple dependencies. You can also substitute forf(t) -> h
and dog(h)
. Now you have a new type! Decoupling means you get fewer types, but more parameters. There is a tradeoff you have to make, both in how types, functions and parameters work.g(f, t)
vsg(f(t))
f(t) -> g
vsf(t) -> g1, f(t) -> g2
self
type? A function or a variable?f(t) -> a
could meana
is a method name, or a new typeg(f(t))
Some examples:
window.title() -> String
becomestitle(window) -> String
. You might considerinfo(window) -> WindowInfo
andtitle(info(window)) -> String
. Perhapstitle(info)(window)
andtitle(info) -> TitleInfo
? Shouldtitle
be a type?It might help solve some problems where you are stuck in the design process and need a way to "sketch up" new ideas.
Semantics
The
->
operator can be thought of as having two sides, one before and one after. When a name appears on the left side but not on the right side, it is assumed to be immutable. When a name appears on the right side with a'
, for examplex'
, it is assumed to be transformed. All objects are functions, and all functions are objects. This means all objects are intended to have a "default" purpose, which can be defined as a function. It is not a strict semantics, but gives a rough idea of how different names/functions relates to each other.For example:
This means
x
is transformed byf
into a new versionx'
.f
might still exist after the transformation, but we don't write it, both to make it shorter and to make it easier to switch to programming thinking. If we do, we write it like this:The arrow does not have mean "returns", it can be side effects of the function. Usually we are interested in the side effects, compositions, and whether one thing needs to depend on another thing.
The text was updated successfully, but these errors were encountered: