Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

20
LINES

< > BotCompany Repo | #1033960 // TypeSystem

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (5927L/33K).

1  
sclass TypeSystem<T> {
2  
  // override if you have supertype (subtype) relations in your type system
3  
  // you can assume neq(a, b)
4  
  swappable bool isActualSupertypeOf(T a, T b) { false; }
5  
  
6  
  bool isSupertypeOf(T a, T b) {
7  
    ret eq(a, b) || isActualSupertypeOf(a, b);
8  
  }
9  
  
10  
  bool operatorCanTakeArguments(GOperator<T> op, T... types) {
11  
    ret matchTwoLists(lambda2 isSupertypeOf,
12  
      reallyLazyMap(op.arguments, a -> a.type()), types);
13  
  }
14  
  
15  
  L<GOperator<T>> resolve(GPolymorphicOperator<T> polyOp, T... types) {
16  
    ret filter(polyOp.definitions, op -> operatorCanTakeArguments(op, types));
17  
  }
18  
  
19  
  swappable S typeToString(T type) { ret str(type); }
20  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 4 computer(s): bhatertpkbcr, ekrmjmnbrukm, mowyntqkapby, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1033960
Snippet name: TypeSystem
Eternal ID of this version: #1033960/7
Text MD5: 3cf7b0d7872e8b22c1fb28196d84929a
Transpilation MD5: 45541a1e26bb7a4266ee448fbac0dfcb
Author: stefan
Category: javax / scripting
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-01-15 02:32:05
Source code size: 682 bytes / 20 lines
Pitched / IR pitched: No / No
Views / Downloads: 88 / 169
Version history: 6 change(s)
Referenced in: [show references]