README.md in haskell-0.1.0 vs README.md in haskell-0.2.0
- old
+ new
@@ -3,21 +3,23 @@
Matz has mentioned Ruby3.0 with static type at some confluences. But almost all rubyists(include me) are not sure how typed Ruby is.
But it's worth thinking more. This gem is kind of trial without so much side-effect.
```rb
-require 'haskell'
+require 'rubype'
-# ex1: (Ruby 2.1.0+)
+# ex1
class MyClass
- type Numeric, Numeric >= Numeric, def sum(x, y)
+ def sum(x, y)
x + y
end
+ typesig sum: [Numeric, Numeric => Numeric]
- type Numeric, Numeric >= Numeric, def wrong_sum(x, y)
+ def wrong_sum(x, y)
'string'
end
+ typesig wrong_sum: [Numeric, Numeric => Numeric]
end
MyClass.new.sum(1, 2)
#=> 3
@@ -26,84 +28,67 @@
MyClass.new.wrong_sum(1, 2)
#=> TypeError: Expected wrong_sum to return Numeric but got "str" instead
-# ex2: (Ruby 2.1.0+)
+# ex2
class People
type People >= Any, def marry(people)
# Your Ruby code as usual
end
end
+typesig marry: [People => Any]
People.new.marry(People.new)
#=> no error
People.new.marry('non people')
#=> ArgumentError: Wrong type of argument, type of "non people" should be People
-
-
-# ex3: (Ruby 1.8.0+)
-class MyClass
- def sum(x, y)
- x + y
- end
- type Numeric, Numeric >= Numeric, :sum
-end
```
## Feature
### Typed method can coexist with non-typed method
```ruby
# It's totally OK!!
class MyClass
- type Numeric, Numeric >= Numeric, def sum(x, y)
+ def sum(x, y)
x + y
end
+ typesig sum: [Numeric, Numeric => Numeric]
- def wrong_sum(x, y)
+ def sum_without_type(x, y)
'string'
end
end
```
### Duck typing
```ruby
class MyClass
- type Any >= Numeric, def foo(any_obj)
+ def foo(any_obj)
1
end
+ typesig sum: [Any => Numeric]
end
# It's totally OK!!
MyClass.new.foo(1)
# It's totally OK!!
MyClass.new.foo('str')
```
## Installation
-Add this line to your application's Gemfile:
+gem install rubype or add gem 'rubype' to your Gemfile.
-```ruby
-gem 'haskell'
-```
+This gem requires Ruby 2.0.0+.
-And then execute:
-
- $ bundle
-
-Or install it yourself as:
-
- $ gem install haskell
-
-
### Contributing
-Fork it ( https://github.com/[my-github-username]/haskell/fork )
+Fork it ( https://github.com/[my-github-username]/rubype/fork )
Create your feature branch (`git checkout -b my-new-feature`)
$ bundle install --path vendor/bundle