Reputation: 31
Preface this with: learning ATS from the ATS web site.
When trying to pull a record out of a list, once I try to reference the record variable I get a type error on x4.a below.
So why does this fail - wouldn't x4 know it has a record?
typedef
abc1_rec = '{a=int, b=int, c=char}
typedef
abc2_rec = '{a=int, b=char, c=string}
val x1 = '{a=1,b=3,c='A'} : abc1_rec // boxed record
val x2 = '{a=1,b='B',c="CAT"} : abc2_rec // boxed record
val a1 = x2.a // =1
val x3 = (x2 :: x1 :: list_nil()) // concat list x2 + x1 + nil
val x4 = x3.head() // record x2
val x5 = x4.a // error - [a] cannot be found
/tmp/patsopt_tcats_lu0auT: 1440(line=77, offs=12) -- 1442(line=77, offs=14): error(3): [a] cannot be found: the type [S2EVar(779)] is expected to be a tyrec(record). patsopt(TRANS3): there are [1] errors in total. exit(ATS): uncaught exception: _2home_2hwxi_2Research_2ATS_2dPostiats_2src_2pats_error_2esats__FatalErrorExn(1025)
Upvotes: 3
Views: 158
Reputation: 935
Note x1 and x2 are of different types. They cannot really be put into the
same list. In this case, the type for x3 is list(X, 2) for some T that is assumed to be a subtype of both abc1_rec
and abc2_rec
; x4 is of the type T, and x4.a gives you a type-error because the typechecker cannot infer that T is a record type.
Upvotes: 1