You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Given how almost everything in nim can be used as a generic parameter type (e.g. distinct) I would have assumed that this also holds true for range to make a generic proc for any range type.
However, this is not possible.
proc isRange(r: range) = echo "is range" can not compile.
Nim Compiler Version 2.0.0 [Linux: amd64]
Compiled at 2023-08-01
Copyright (c) 2006-2023 by Andreas Rumpf
git hash: a488067
active boot switches: -d:release
Current Output
Error: invalid type: 'range' in this context: 'proc (r: range)' for proc
Expected Output
No compiler error
Possible Solution
I only have a temporary solution for anyone running into this:
You can use a concept (Thanks to ElegantBeef for the suggestion!)
typeRange=concept r
r israngeprocisRange(r: Range) =echo"is range"let y: range[0..10] =5
y.isRange()
Additional Information
I am not 100% certain if this is actually a bug or me not having deep enough an understanding of typeclasses etc.
I currently assume it is a bug, because inverse of range (not range) somehow does act as a valid generic parameter type.
procisRange(r: notrange) =echo"is not range"let y =5
y.isRange()
This further solidified my assumption that proc isRange(r: range) should be possible.
Also this may be related to #17423 ?
I don't fully understand it but very distantly the issue seems maybe similar enough?
The text was updated successfully, but these errors were encountered:
Error: ambiguous call; both playground.isRange(r: T: range) [proc declared in /home/philipp/dev/playground/src/playground.nim(1, 6)] and playground.isRange(r: GenericParam) [proc declared in /home/philipp/dev/playground/src/playground.nim(2, 6)] match for: (range 1..10(int))
Description
Given how almost everything in nim can be used as a generic parameter type (e.g.
distinct
) I would have assumed that this also holds true forrange
to make a generic proc for anyrange
type.However, this is not possible.
proc isRange(r: range) = echo "is range"
can not compile.Thus this code-snippet can not compile:
Nim Version
Nim Compiler Version 2.0.0 [Linux: amd64]
Compiled at 2023-08-01
Copyright (c) 2006-2023 by Andreas Rumpf
git hash: a488067
active boot switches: -d:release
Current Output
Expected Output
Possible Solution
I only have a temporary solution for anyone running into this:
You can use a concept (Thanks to ElegantBeef for the suggestion!)
Additional Information
I am not 100% certain if this is actually a bug or me not having deep enough an understanding of typeclasses etc.
I currently assume it is a bug, because inverse of
range
(not range
) somehow does act as a valid generic parameter type.This further solidified my assumption that
proc isRange(r: range)
should be possible.Also this may be related to #17423 ?
I don't fully understand it but very distantly the issue seems maybe similar enough?
The text was updated successfully, but these errors were encountered: