Skip to content

Commit

Permalink
modified readme
Browse files Browse the repository at this point in the history
  • Loading branch information
urumo committed Jan 22, 2024
1 parent cd017f6 commit 62fcb1c
Showing 1 changed file with 70 additions and 48 deletions.
118 changes: 70 additions & 48 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,49 +1,71 @@
# RubyTypeSystem

TODO: Delete this and the text below, and describe your gem

Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library
into a gem. Put your Ruby code in the file `lib/ruby_type_system`. To experiment with that code, run `bin/console` for
an interactive prompt.

## Installation

TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after
releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section
with instructions to install your gem from git if you don't plan to release to RubyGems.org.

Install the gem and add to the application's Gemfile by executing:

$ bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG

If bundler is not being used to manage dependencies, install the gem by executing:

$ gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG

## Usage

TODO: Write usage instructions here

## Development

After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can
also run `bin/console` for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the
version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version,
push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).

## Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/ruby_type_system. This project is
intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to
the [code of conduct](https://github.com/[USERNAME]/ruby_type_system/blob/main/CODE_OF_CONDUCT.md).

## License

The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).

## Code of Conduct

Everyone interacting in the RubyTypeSystem project's codebases, issue trackers, chat rooms and mailing lists is expected
to follow the [code of conduct](https://github.com/[USERNAME]/ruby_type_system/blob/main/CODE_OF_CONDUCT.md).
### A Work in progress type system for Ruby

## Current state
* Ruby is a mature language with a lot of libraries and a lot of code written in it.
* Ruby is a dynamically typed language, which means that the type of a variable is not known until runtime or is known only in the mind of the developer.
* What ruby lacks is a type system, which is a set of rules that define what types are allowed in a program.
* Solutions like `Sorbet` and `RBS` exist, but they are not part of the language itself and are not widely used. They have their pros and cons.
* The problem with `RBS` is that you have to write a lot of boilerplate code to define types that are only a hint for you favorite IDE.
* The problem with `Sorbet` is that it's not very intuitive and you have to take time to learn and get used to the way it works.

## General idea
The RubyTypeSystem project aims to create an intuitive and easy-to-use type system for Ruby. The main ideas behind this project are:

1. **Intuitive Types**: The types used in this system come from the Ruby standard library. This makes the system intuitive for developers who are already familiar with Ruby.

2. **Type Inference**: The system will take care of most of the typing through type inference. This reduces the amount of type annotations that developers need to write, making the code cleaner and easier to read.

3. **Method Typing**: Despite the type inference, methods will still require typing. This ensures that the behavior of methods is clear and predictable.

4. **New Keywords**: The system introduces new keywords to describe interfaces, abstract classes, union types, and types in general. These keywords extend the Ruby language with powerful features for static typing.

## Some examples
### Type inference
```ruby
some_int: Integer = 1
some_float = some_method_that_returns_float # The compiler assumes a Float type
some_int + some_float # CompileTimeError
```
### Method typing
```ruby
def some_method(a: Integer, b: Integer): Integer
a + b
end
```
A more experienced developer would argue "But how are we going to introduce default values for parameters" and that is a great question.
Let's take the following ruby code as an example:
```ruby
def a(some_val = 1)
some_val + 1
end

def b(key: 'key', value: 'value')
"#{key}: #{value}"
end
```
In this example we have two methods, both have parameters with default values, but the first method has a positional parameter and the second method has keyword parameters.
In case of positional parameters the following code is equivalent:
```ruby
def a(some_val: Integer = 1): Integer
some_val + 1
end
```
In case of keyword parameters the following code is equivalent:
```ruby
def b([key: String]: 'key', [value: String]: 'value'): String # this approach is up for debate, you can propose a better way in the issues section
"#{key}: #{value}"
end
```
## How it works
The RubyTypeSystem is a work in progress. More details will be added as the project evolves.
=
## Milestones
- [x] Create a compressor, that compresses the source codes down to a single file
- [x] Create a lexer
- [ ] Create a parser that produces an AST
- [ ] Create a type checker
- [ ] Create a type inference engine
- [ ] Create a compiler
- [ ] Create an Optimizer to optimize the compiled code down to a single expression

0 comments on commit 62fcb1c

Please sign in to comment.