Permalink
Browse files

Subtyping: SA-Arrow

  • Loading branch information...
urbanautomaton committed Oct 10, 2017
1 parent a4a7b67 commit 3577e2641b2723b2beb606830e8df0d8d223ad0a
Showing with 28 additions and 0 deletions.
  1. +6 −0 lib/simple_types.rb
  2. +22 −0 spec/simple_types_spec.rb
@@ -9,6 +9,12 @@ def subtype_of?(subtype, supertype)
subtype.members.key?(field) && subtype_of?(subtype.members[field], type)
end
end
if subtype.is_a?(Type::Function) && supertype.is_a?(Type::Function)
return (
subtype_of?(supertype.from, subtype.from) &&
subtype_of?(subtype.to, supertype.to)
)
end
false
end
@@ -51,6 +51,28 @@
end
end
describe 'SA-ARROW' do
specify do
expect('Bool -> Bool').to be_subtype_of('Bool -> Bool')
end
specify do
expect('Bool -> Bool').to be_subtype_of('Bool -> Top')
end
specify do
expect('Top -> Bool').to be_subtype_of('Bool -> Bool')
end
specify do
expect('Bool -> Top').not_to be_subtype_of('Bool -> Bool')
end
specify do
expect('Bool -> Bool').not_to be_subtype_of('Top -> Bool')
end
end
def expr(text)
Parser.parse(text)
end

0 comments on commit 3577e26

Please sign in to comment.