Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Subtyping: SA-Arrow
  • Loading branch information
urbanautomaton committed Oct 11, 2017
1 parent a4a7b67 commit 3577e26
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/simple_types.rb
Expand Up @@ -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

Expand Down
22 changes: 22 additions & 0 deletions spec/simple_types_spec.rb
Expand Up @@ -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
Expand Down

0 comments on commit 3577e26

Please sign in to comment.