# Castile / src / castile / types.py

 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65``` ```class Type(object): # Note: type equality relies on (str), so we can't directly # compare infinite types. But with structs, we shouldn't have to. def __eq__(self, other): return str(self) == str(other) def __ne__(self, other): return str(self) != str(other) class Void(Type): def __str__(self): return "void" class Integer(Type): def __str__(self): return "integer" class String(Type): def __str__(self): return "string" class Boolean(Type): def __str__(self): return "boolean" class Function(Type): def __init__(self, arg_types, return_type): self.arg_types = arg_types self.return_type = return_type def __str__(self): h = "function(" h += ', '.join([str(t) for t in self.arg_types]) h += '): ' + str(self.return_type) return h class Struct(Type): def __init__(self, name): self.name = name def __str__(self): return "struct %s" % self.name class Union(Type): def __init__(self, content_types): self.content_types = content_types def contains(self, type): for member in self.content_types: if type == member: return True return False def __str__(self): h = "union(" h += ', '.join(sorted([str(t) for t in self.content_types])) h += ')' return h ```