User loginNavigation |
Stronger relationships between structuresLets say you're compiler uses the following structures to represent a function type and a class to represent a function declaration: class FuncType extends Type { List<Type> params; Type ret; } class FuncDecl { String name; FuncType type; List<String> paramNames; } There objects "FuncDecl.type.params" and "FuncDecl.paramNames" are related in ways that aren't expressed in the source code of the two class declarations. For example, each entry in the "paramNames" list matches up with the corresponding type in the "type.params" list. I've been thinking about "paramNames" as adding attributes to the "FuncType" data structure. So paramNames would actually be a "map" data structure whose keys are structural references to parameter types and whose values are strings. Something like: class FuncDecl { String name; FuncType type; Map<#type#,String> paramNames; } FuncDecl d = ...; d.paramNames.put(#params[0]#", "dst"); // The "params" refers to the list in "type" d.paramNames.put(#params[1]#", "src"); ... The best concrete solution I can come up with isn't satisfying: class FuncType<ExtraParamInfo,ExtraReturnInfo> { List<Pair<Type,ExtraParamInfo>> paramets; Pair<Type,ExtraReturnInfo> ret; } class FuncDecl { Type<String,Void> typeAndParamNames; } Is there a language or type system that does a good job of expressing such relationships? By Kannan Goundan at 2007-02-06 09:47 | LtU Forum | previous forum topic | next forum topic | other blogs | 4576 reads
|
Browse archives
Active forum topics |
Recent comments
27 weeks 1 day ago
27 weeks 2 days ago
27 weeks 2 days ago
49 weeks 3 days ago
1 year 1 week ago
1 year 3 weeks ago
1 year 3 weeks ago
1 year 5 weeks ago
1 year 10 weeks ago
1 year 10 weeks ago