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

how to create an IntSet on the heap in nim?
How to benchmark few lines of code in nim?
what is nim type definition for generic procedure?
Does a nim library contain an argsort implementation or wrapper?
nim jester how to change static route and directory
nim linker error while linking to libsodium
Can countup and countdown iterators in Nim language be used in variable declaration?
How do I write unit test for code that should fail to compile in Nim?
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?

Categories

HOME
asp.net-web-api
api
toolbox
error-handling
seo
nsbundle
scripting
vert.x
nstableheaderview
elasticsearch-5
computer-science
minecraft-forge
commonjs
android-securityexception
line
code-generation
gource
do-while
google-picker
soci
imagemap
gulp-watch
beta
dapper-extensions
definitelytyped
syntax-highlighting
oculus
apktool
linked-data
sinch
errbot
jaws
fstream
hreflang
twos-complement
numpy-broadcasting
servicestack-text
plaintext
vmware-fusion
install.packages
bindingnavigator
tcc
memory-mapping
x++
sonarlint-eclipse
robomongo
dotnet-httpclient
mongotemplate
lightning
semantic-logging
context-sensitive-grammar
check-mk
payload
template-toolkit
stripe-connect
atlas
pytables
reporting-services-2012
dotnetnuke-7
mta
i386
android-dateutils
omniauth-facebook
phpwebsocket
yajsw
httpruntime.cache
contentcontrol
user-management
highland.js
ess
video-player
pax-exam
public-html
openbabel
delayed-execution
dbaccess
packet-sniffers
android-vibration
rmysql
lnk
xml-dsig
winginx
conditionaltagsupport
ecslidingviewcontroller
artemis
scrypt
c++builder-xe5
jeromq
hidapi
facebook-timeline
pclzip
http-status-code-410
wcf-configuration
koken
cgimage
gobject-introspection
saxparseexception
u2netdk
dataform
instantiationexception
vs-android
lxr
strtod
complex-event-processing
dojo-dnd
dsoframer
leader

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