-
Notifications
You must be signed in to change notification settings - Fork 4
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.
- Getting started
- Language basics
- The type system and built-in functions
- Functional Pipefish
- Encapsulation
- Imperative Pipefish
-
Imports and libraries
- The crypto/aes library
- The crypto/bcrypt library
- The crypto/rand library
- The crypto/rsa library
- The crypto/sha_256 library
- The crypto/sha_512 library
- The database/sql library
- The encoding/base_32 library
- The encoding/base_64 library
- The encoding/csv library
- The encoding/json library
- The files library
- The fmt library
- The html library
- The image library
- The image/bmp library
- The image/color library
- The image/jpeg library
- The image/png library
- The lists library
- The markdown library
- The math library
- The math/big library
- The math/cmplx library
- The math/rand library
- The net/http library
- The net/mail library
- The net/smtp library
- The net/url library
- The os/exec library
- The path library
- The path/filepath library
- The reflect library
- The regexp library
- The strconv library
- The strings library
- The terminal library
- The time library
- The unicode library
- Advanced Pipefish
- Developing in Pipefish
- Deployment
- Appendices