Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Abstract versus concrete types #430

Open
dumblob opened this issue Jul 8, 2015 · 0 comments
Open

Abstract versus concrete types #430

dumblob opened this issue Jul 8, 2015 · 0 comments

Comments

@dumblob
Copy link

dumblob commented Jul 8, 2015

I wonder, why all purely "abstract" types (list tuple map array enum) can't be matched against concrete versions of them (e.g. list<int> tuple<string, int> map<int, string> array<int> enum<a, b>). Is there any reason for that? Currently it feels more like some magic:

l = {1,'x'}
if ( l ?< list )
  io.writeln('do match', std.about(l))
else
  io.writeln('do NOT match', std.about(l))

#t = (1,'x')
#if ( t ?< tuple )
#  io.writeln('do match', std.about(t))
#else
#  io.writeln('do NOT match', std.about(t))

m = {1->'x'}
if ( m ?< map )
  io.writeln('do match', std.about(m))
else
  io.writeln('do NOT match', std.about(m))

m2 = {1=>'x'}
if ( m2 ?< map )
  io.writeln('do match', std.about(m2))
else
  io.writeln('do NOT match', std.about(m2))

a = array{1,2}
if ( a ?< array )
  io.writeln('do match', std.about(a))
else
  io.writeln('do NOT match', std.about(a))

e = (enum<x,y>)$x
if ( e ?< enum )
  io.writeln('do match', std.about(e))
else
  io.writeln('do NOT match', std.about(e))

gives:

do match list<any>[0x7dad30]:list<any>
do NOT match map<int,string>[0x7daf20]:map<int,string>
do NOT match map<int,string>[0x810f90]:map<int,string>
do NOT match array<int>[0x7f4bf0]:array<int>
do match enum<x,y>[0x7b4200]:enum<x,y>

and with the commented lines uncommented:

[[ERROR]] in file "/home/test/test.dao":
  At line 8 : Invalid expression --- " t ?< tuple ";
  At line 8 : Invalid expression --- " t ?< tuple ) ";
  At line 8 : Symbol not defined --- " tuple ";

This error with tuple is quite surprising, because x: tuple<int> = (5,) and x: tuple = (5,) works like a charm.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant