Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Random: proc rand(x: HSlice) requires substraction #7698

Closed
mratsim opened this issue Apr 27, 2018 · 3 comments
Closed

Random: proc rand(x: HSlice) requires substraction #7698

mratsim opened this issue Apr 27, 2018 · 3 comments

Comments

@mratsim
Copy link
Collaborator

mratsim commented Apr 27, 2018

Currently it is not possible to use rand with slices of char or enum:

import random

let slice = '0'..'F'
let r = rand(cslice)
Error: type mismatch: got <char, char>
but expected one of:
proc `-`[T](x, y: set[T]): set[T]
...
type
  Op = enum
    Halt
    Inc
    Dec

import random

let opslice = Halt..Dec
let op = rand(opslice)

Same error

@Araq
Copy link
Member

Araq commented Apr 27, 2018

But if we support enum the code could produce invalid values for enums with holes.

@mratsim
Copy link
Collaborator Author

mratsim commented Apr 27, 2018

Then I think the signature should be T: SomeInteger.

@Araq
Copy link
Member

Araq commented Apr 27, 2018

Fine with me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants