nim


Program doesn't compile when “concept” defines a method with a parameter


I have a concept like this:
type Foo = concept x, y
x.test(y) is bool
And then a type that tries to define a method that implements the concept:
type Bar = object
s: string
proc test(x: Bar, y: string): bool =
x.s == y
And a type that has a generic field T: Foo with a constructor that receives a T: Foo:
type Baz[T: Foo] = object
f: T
proc make[T: Foo](f: T): auto =
result = Baz[T](f: f)
When I create a new Bar and pass it to the make proc to make a new Baz, it doesn't compile:
let bar = Bar(s: "whatever")
let made = make[Bar](bar)
Error: type mismatch: got (Bar) but expected 'T'
However it compiles if I drop the y in the concept, like x.test is bool and update the test proc accordingly.
What am I doing wrong?
Change
type Foo = concept x, y
x.test(y) is bool
To
type Foo = concept x
x.test(string) is bool
In your code, it means x and y are both Foo type. If you really means that, please try this.
proc test(x: Bar, y: Bar): bool =
x.s == y.s

Related Links

Difference between void proc and void proc with discard
nim nimscript is not executing commands
Remove element at index from sequence
Is it possible / easy to include some mruby in a nim application?
Reading bytes from many files performance
Program doesn't compile when “concept” defines a method with a parameter
How do I create a directory?
Why is my string nil?
Nim code parser
What's the meaning of “magic” pragma in nim?
Unpack multiple variables from sequence
Nim: How to prove not nil?
Error: expression has no address
MD5 on an array, array[0..63, uint8] to cstring conversion
Converting a seq[char] to string
Nim: On mac, cannot open standard import

Categories

HOME
sonarqube
embedded
porting
jpa
cheerio
webdriver
youtube-data-api-v3
shiro
seo
yandex
alsa
google-admin-sdk
webix
boto3
character
sendgrid-api-v3
categorical-data
openpyxl
mel
line
azure-iot-hub
microsoft-dynamics-nav
fileserver
shortest-path
apache2.4
r-mice
event-store
qliksense
android-maps
linked-data
openmdao
alm
userdefaults
erb
pop3
getlasterror
sharepoint-workflow
parse-tree
playframework-2.1
zoomify
git-rewrite-history
cin
signals-slots
azure-arm
laravel-elixir
glm-math
contract
apache-spark-dataset
builder
clarifai
serde
podscms
aquamacs
oracleclient
edit
er-diagram
flyout
flac
objectscript
polyline
rocks
mapxtreme
reporting-services-2012
hadoop-2.7.2
tinkerpop3
avspeechsynthesizer
jtwig
nupic
kendo-upload
concept-insights
state-restoration
assertion
file-move
vigenere
lazybones
google-books
extjs-grid
pax-exam
dnssec
nutiteq
node-serialport
device-tree
with-statement
live555
buffering
ora-06550
jeromq
script#
rolify
dolby-audio-api
insert-id
idn
qi4j
midlet
floating-point-exceptions
ikimagebrowserview
multiplatform
umra
lalr
mathematical-typesetting
pnrp

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App