Created
April 4, 2017 07:25
-
-
Save dustinlacewell/682a6a17d41e393a9dad95997cce185b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type | |
Comparable = concept x, y | |
x < y is bool | |
x > y is bool | |
Value[T] = concept v | |
v.value is T | |
set(v, v.value) is bool | |
DefaultValue[T] = concept v | |
v is Value | |
v.default is T | |
RangedValue[T] = concept v | |
v is DefaultValue | |
v.min is T | |
v.max is T | |
BoolValue = ref object | |
default*: bool | |
value: bool | |
FloatValue = ref object | |
min*, max*: float | |
default*: float | |
value: float | |
proc set[T, V](t: T, v: V): bool = | |
when compiles(t.min): | |
if v < t.min: return false | |
when compiles(t.max): | |
if v > t.max: return false | |
t.value = v | |
return true | |
let | |
b: BoolValue = new(BoolValue) | |
f: FloatValue = new(FloatValue) | |
discard b.set(false) | |
discard f.set(10.0) | |
when BoolValue is Value:# and BoolValue is RangedValue[bool]: | |
echo "BoolValue is good" | |
when FloatValue is Value:# and FloatValue is RangedValue[float]: | |
echo "FloatValue is good" | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
synth.nim(43, 10) Error: type mismatch: got (bool, BoolValue) | |
but expected one of: | |
proc `<`[T](x: Ordinal[T]): T | |
proc `<`[T](x, y: ptr T): bool | |
proc `<`(x, y: int32): bool | |
proc `<`(x, y: float): bool | |
proc `<`(x, y: char): bool | |
proc `<`[T](x, y: set[T]): bool | |
proc `<`(x, y: float32): bool | |
proc `<`(x, y: int16): bool | |
proc `<`(x, y: pointer): bool | |
proc `<`[Enum: enum](x, y: Enum): bool | |
proc `<`[T: tuple](x, y: T): bool | |
proc `<`(x, y: string): bool | |
proc `<`[T: SomeUnsignedInt](x, y: T): bool | |
proc `<`(x, y: int8): bool | |
proc `<`(x, y: int): bool | |
proc `<`(x, y: bool): bool | |
proc `<`[T](x, y: ref T): bool | |
proc `<`(x, y: int64): bool | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment