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 | 4559 reads
|
Browse archives
Active forum topics |
Recent comments
22 weeks 6 days ago
22 weeks 6 days ago
22 weeks 6 days ago
45 weeks 19 hours ago
49 weeks 2 days ago
50 weeks 6 days ago
50 weeks 6 days ago
1 year 1 week ago
1 year 6 weeks ago
1 year 6 weeks ago