dao
dao copied to clipboard
Abstract versus concrete types
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.