Playground link: https://play.nim-lang.org/#ix=2L5x
Why cannot I use incl for my following type?
type
Shift* = object
quoted*: bool
date*: DateTime
description*: string
start*: Option[DateTime]
finish*: Option[DateTime]
breakTime*: Option[Duration]
rate*: float
qty: Option[float]
Compiler error message did not make sense to me:
/usercode/in.nim(82, 7) template/generic instantiation of `incl` from here
/playground/nim/lib/pure/collections/setimpl.nim(49, 21) template/generic instantiation of `rawGet` from here
/playground/nim/lib/pure/collections/hashcommon.nim(79, 14) template/generic instantiation of `genHashImpl` from here
/playground/nim/lib/pure/collections/hashcommon.nim(69, 12) Error: type mismatch: got <Shift>
but expected one of:
proc hash(sBuf: string; sPos, ePos: int): Hash
first type mismatch at position: 1
required type for sBuf: string
but expression 'key' is of type: Shift
proc hash(x: cstring): Hash
first type mismatch at position: 1
required type for x: cstring
but expression 'key' is of type: Shift
proc hash(x: float): Hash
first type mismatch at position: 1
required type for x: float
but expression 'key' is of type: Shift
proc hash(x: pointer): Hash
first type mismatch at position: 1
required type for x: pointer
but expression 'key' is of type: Shift
proc hash(x: string): Hash
first type mismatch at position: 1
required type for x: string
but expression 'key' is of type: Shift
proc hash[A](aBuf: openArray[A]; sPos, ePos: int): Hash
first type mismatch at position: 1
required type for aBuf: openArray[A]
but expression 'key' is of type: Shift
proc hash[A](s: HashSet[A]): Hash
first type mismatch at position: 1
required type for s: HashSet[hash.A]
but expression 'key' is of type: Shift
proc hash[A](s: OrderedSet[A]): Hash
first type mismatch at position: 1
required type for s: OrderedSet[hash.A]
but expression 'key' is of type: Shift
proc hash[A](x: openArray[A]): Hash
first type mismatch at position: 1
required type for x: openArray[A]
but expression 'key' is of type: Shift
proc hash[A](x: set[A]): Hash
first type mismatch at position: 1
required type for x: set[A]
but expression 'key' is of type: Shift
proc hash[T: Ordinal | enum](x: T): Hash
first type mismatch at position: 1
required type for x: T: Ordinal or enum
but expression 'key' is of type: Shift
proc hash[T: proc](x: T): Hash
first type mismatch at position: 1
required type for x: T: proc
but expression 'key' is of type: Shift
proc hash[T: tuple](x: T): Hash
first type mismatch at position: 1
required type for x: T: tuple
but expression 'key' is of type: Shift
expression: hash(key)
I always wondered, why is there no generic Hash in stdlib like:
proc hash[T: object | ref object](o: T): Hash =
var h: Hash = 0
for k, v in o.fieldPairs:
h = h !& v.hash
result = !$h