I have a couple of modules : mdlimpl, mdlabst and mdlprog. mdlimpl implements
(you guess it) some basic functionality. mdlabst (abstraction) imports mdlimpl
and operates on a type `TOb` given by mdlimpl, but the type gets not revealed
in mdlabst. To achieve this, functions defined by mdlimpl only are used. Last
not least, mdlprog imports mdlabst but not mdlimpl.
#mdlimpl
type
TOb* = object
a*, 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
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
type
Tcr = concept x, type T
x.b is int
proc reif(x:Tcr) =
echo x
proc run() =
var v : Tcon = con(5)
v.b = v.b + 5
reif v
run()
Run