typed.rb 0.0.13 → 0.0.14

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b580e881ef45c47047651872f06cabfeeef3bc14
4
- data.tar.gz: 98b117dcde88dab1eeeaeee8a62b9ad147f0121b
3
+ metadata.gz: 10a8acbaa2e89eb19d043a4b29ccc1a9e9f58712
4
+ data.tar.gz: 5cfd5c3ee30993b30d82558d168c675c2fe6b859
5
5
  SHA512:
6
- metadata.gz: bb62808c4d511ce344ef7cba6872aa99b827ad9e353fde28c9b8add4ae22f53c4b1e9176efa51a3596439ddfee33df2a09e6d86dea23d8028e5bbf733c92d7f5
7
- data.tar.gz: 812be8a32afa7597ce926dbafdee7baed49debe401186bac5f9c3eed3ab2da901bfceaacf2651530fbebc1a25cb412b288cfa3b7c51fee46d71967b212adb8c8
6
+ metadata.gz: 3233c50ea7798b565d1b5a24ded1a608a5b018821e47b390788ceb3108d183970a726622c973e31f3fbbae64d33faf70fe3bc376888a134df62d2772500a19e7
7
+ data.tar.gz: 8b0e4212b51a79d643e682618cbbee275a4dbeb2f762d9aeabc14c633f2a1e682e948a5a23c31ebe26a78d889bcf9f56f0a3304cadccd7c4a53d71e4f2e7ab27
data/README.md ADDED
@@ -0,0 +1,55 @@
1
+ #Typed.rb [![Build Status](https://circleci.com/gh/antoniogarrote/typed.rb.png?circle-token=:circle-token)](https://circleci.com/gh/antoniogarrote/typed.rb/tree/master)
2
+
3
+ Gradual type checker for Ruby.
4
+
5
+ Example from `spec/lib/examples/monoid.rb`:
6
+
7
+ ```ruby
8
+ require 'typed/runtime'
9
+
10
+ ts 'type Monoid[T]'
11
+ module Monoid
12
+
13
+ ts '#mappend / [T] -> [T] -> [T]'
14
+ abstract(:mappend)
15
+
16
+ ts '#mempty / -> [T]'
17
+ abstract(:mempty)
18
+
19
+ end
20
+
21
+
22
+ ts 'type Sum[Integer] super Monoid[T]'
23
+ class Sum
24
+
25
+ include Monoid
26
+
27
+ def mappend(a,b)
28
+ a + b
29
+ end
30
+
31
+ def mempty
32
+ 0
33
+ end
34
+
35
+ end
36
+
37
+
38
+ ts '#sum / Array[Integer] -> Integer'
39
+ def sum(xs)
40
+ monoid = Sum.new
41
+ zero = monoid.mempty
42
+ xs.reduce(zero) { |a,b| monoid.mappend(a,b) }
43
+ end
44
+
45
+
46
+ ts '#moncat[T] / Array[T] -> Monoid[T] -> [T]'
47
+ def moncat(xs, m)
48
+ zero = m.mempty
49
+ xs.reduce(zero) { |a,b| m.mappend(a,b) }
50
+ end
51
+
52
+ ->() {
53
+ moncat([1,2,3], Sum.new)
54
+ }
55
+ ```
data/bin/typed.rb CHANGED
@@ -1,6 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
2
  # encoding: utf-8
3
- require 'pry'
4
3
  require_relative '../lib/typed'
5
4
  require 'benchmark'
6
5
  require 'set'
@@ -135,6 +134,8 @@ time = Benchmark.realtime do
135
134
  begin
136
135
  files_to_check = TargetFinder.new.find(ARGV).reject { |f| f == File.expand_path(__FILE__) }
137
136
  TypedRb::Language.new.check_files(files_to_check, true)
137
+ rescue TypedRb::Types::TypeParsingError => e
138
+ raise e
138
139
  rescue TypedRb::TypeCheckError => e
139
140
  success = false
140
141
  end
@@ -145,4 +146,4 @@ if success == false
145
146
  exit(1)
146
147
  else
147
148
  exit(0)
148
- end
149
+ end
Binary file
data/lib/typed/runtime.rb CHANGED
@@ -23,6 +23,11 @@ class BasicObject
23
23
  # noop
24
24
  from
25
25
  end
26
+
27
+ ts '#abstract / Symbol -> Symbol'
28
+ def abstract(name)
29
+ define_method(name) { |*args| raise "Invoking abstract method #{name}"}
30
+ end
26
31
  end
27
32
 
28
33
  class Class
@@ -123,10 +123,11 @@ module TypedRb
123
123
  def add_type_var_constraint(type_var, other_type_var, relation)
124
124
  if type_var.bound
125
125
  type_var, other_type_var = other_type_var, type_var
126
- relation = relation == :lt ? :gt : :lt
126
+ #relation = relation == :lt ? :gt : :lt
127
+ end
128
+ [:lt, :gt].each do |relation|
129
+ type_var.add_constraint(relation, other_type_var.bound)
127
130
  end
128
- type_var.add_constraint(relation, other_type_var.bound)
129
- true
130
131
  end
131
132
  end
132
133
  end
data/lib/typed/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module TypedRb
2
- VERSION = '0.0.13'
2
+ VERSION = '0.0.14'
3
3
  end
@@ -0,0 +1,44 @@
1
+ ts 'type Monoid[T]'
2
+ module Monoid
3
+ ts '#mappend / [T] -> [T] -> [T]'
4
+ abstract(:mappend)
5
+
6
+ ts '#mempty / -> [T]'
7
+ abstract(:mempty)
8
+ end
9
+
10
+
11
+ ts 'type Sum[Integer] super Monoid[T]'
12
+ class Sum
13
+
14
+ include Monoid
15
+
16
+ def mappend(a,b)
17
+ a + b
18
+ end
19
+
20
+ def mempty
21
+ 0
22
+ end
23
+
24
+ end
25
+
26
+
27
+ ts '#sum / Array[Integer] -> Integer'
28
+ def sum(xs)
29
+ monoid = Sum.new
30
+ zero = monoid.mempty
31
+ xs.reduce(zero) { |a,b| monoid.mappend(a,b) }
32
+ end
33
+
34
+
35
+ ts '#moncat[T] / Array[T] -> Monoid[T] -> [T]'
36
+ def moncat(xs, m)
37
+ zero = m.mempty
38
+ xs.reduce(zero) { |a,b| m.mappend(a,b) }
39
+ end
40
+
41
+ ->() {
42
+ moncat([1,2,3], Sum.new)
43
+ }
44
+
@@ -49,4 +49,16 @@ describe TypedRb::Language do
49
49
  /Error type checking message sent 'mindless_func': Array\[Animal1\] expected, Array\[Cat1\] found/)
50
50
  end
51
51
  end
52
+
53
+ context 'with monoid eample' do
54
+ let(:example) { 'monoid.rb' }
55
+
56
+ it 'should be possible to type check the example correctly' do
57
+ expect {
58
+ silence_stream(STDOUT) do
59
+ language.check_file(file, true)
60
+ end
61
+ }.not_to raise_error
62
+ end
63
+ end
52
64
  end
metadata CHANGED
@@ -1,15 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: typed.rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.13
4
+ version: 0.0.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Antonio Garrote
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-19 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2016-01-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: parser
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: log4r
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: colorize
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.7'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.7'
13
55
  description:
14
56
  email: antoniogarrote@gmail.com
15
57
  executables:
@@ -17,6 +59,7 @@ executables:
17
59
  extensions: []
18
60
  extra_rdoc_files: []
19
61
  files:
62
+ - README.md
20
63
  - Rakefile
21
64
  - bin/typed.rb
22
65
  - lib/typed.rb
@@ -104,6 +147,7 @@ files:
104
147
  - spec/lib/examples/animals.rb
105
148
  - spec/lib/examples/counter.rb
106
149
  - spec/lib/examples/if.rb
150
+ - spec/lib/examples/monoid.rb
107
151
  - spec/lib/language_spec.rb
108
152
  - spec/lib/model/tm_abs_spec.rb
109
153
  - spec/lib/model/tm_array_literal_spec.rb
@@ -208,9 +252,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
208
252
  version: '0'
209
253
  requirements: []
210
254
  rubyforge_project:
211
- rubygems_version: 2.4.6
255
+ rubygems_version: 2.4.5.1
212
256
  signing_key:
213
257
  specification_version: 4
214
258
  summary: Gradual type checker for Ruby
215
259
  test_files: []
216
- has_rdoc: