-
Notifications
You must be signed in to change notification settings - Fork 6
Interface types, part 1
An interface type defines an abstract type by saying that it is the union of all the concrete types with a given function or collection of functions defined on them.
For example, there are a number of built-in types for your convenience, such as
Addable = interface :
(x self) + (y self) -> self
This includes every type with an operation which adds a value of that type to another value of thaat type and returns a values of the same type. So it contains at least int
, float
, list
, string
and set
, and then whatever other types you decide to define addition on.
You can also define your own interface types as you please:
Foobarable = interface :
foo(x self, y int) -> self
bar(x self) -> bool
Besides just defining abstract types they play another role, but we will discuss this on a later page, after we have introduced modules.
##The built-in interfaces
The built-in interfaces are as follows:
Addable = interface :
(x self) + (y self) -> self
Comparable = interface :
(x self) < (y self) -> bool
(x self) <= (y self) -> bool
(x self) > (y self) -> bool
(x self) >= (y self) -> bool
Dividable = interface :
(x self) / (y self) -> self
Lennable = interface :
len(x self) -> int
Multipliable = interface :
(x self) * (y self) -> self
Negatable = interface :
-(x self) -> self
Stringable = interface :
string(x self) -> string
Subtractable = interface :
(x self) - (y self) -> self
🧿 Pipefish is distributed under the MIT license. Please steal my code and ideas.