Skip to content

Instantly share code, notes, and snippets.

@apahl
Created September 25, 2018 09:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save apahl/a23280267324baf7f2769ad692d563a8 to your computer and use it in GitHub Desktop.
Save apahl/a23280267324baf7f2769ad692d563a8 to your computer and use it in GitHub Desktop.
Do I have to implement a hash for my enum?
import tables
type
Element* {.pure.} = enum
invalid = (-1, "Inv"),
unknown = (0, "*"),
hydrogen = (1, "H"),
boron = (5, "B"),
carbon = (6, "C"),
nitrogen = (7, "N"),
oxygen = (8, "O"),
fluorine = (9, "F"),
phosphorus = (15, "P"),
sulfur = (16, "S"),
chlorine = (17, "Cl"),
bromine = (35, "Br"),
iodine = (53, "I")
let Valencies*: Table[Element, set[int8]] =
{
hydrogen: {1.int8},
boron: {3.int8},
carbon: {4.int8},
nitrogen: {3.int8, 5},
oxygen: {2.int8}
}.toTable
#[ The error message:
type mismatch: got <Element>
but expected one of:
proc hash(x: char): Hash
proc hash(x: float): Hash
proc hash[A](aBuf: openArray[A]; sPos, ePos: int): Hash
proc hash(x: int64): Hash
proc hash[T: tuple](x: T): Hash
proc hash(sBuf: string; sPos, ePos: int): Hash
proc hash[T: proc](x: T): Hash
proc hash(x: int): Hash
proc hash[T: Ordinal](x: T): Hash
proc hash(x: cstring): Hash]#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment