> Unfortunately, run() does not have access to any of the abstract
> (constructor, operator) functions provided by mdlimpl. This is bizarre
> because Tcon , provided and exported by mdlabst , just checked that they are
> available!
The job of `Tcon` is to check whether `TOb` supports a certain API, not to make
that API accessible:
#mdlimpl
type
TOb* = object
a : int
b : int
proc oinit*(x : int) : TOb = TOb(a:x,b:0)
proc oopn*(obj : TOb , x : int) : TOb = TOb(a:obj.a, b: obj.a+x)
proc oprint*(obj : TOb) = echo obj
#mdlabst
import mdlimpl
export mdlimpl.oinit, mdlimpl.oopn, mdlimpl.oprint
type
Tcon* = concept x,type T
oinit(int) is T
oopn(x,int) is T
oprint(x)
proc reif(x:Tcon) = oprint(x)
proc con*(x :int) : Tcon =
result = oinit(x)
result = oopn(result,2)
reif result
#mdlprog
import mdlabst
proc run() =
var v : Tcon = con(5)
v = oopn(v, 5) # should probably have been `v.b = v.a + 5` in the
original code
oprint(v)
run()
Run
Is that the separation you wanted?