Not that it's useful, but it would be very cool to be able to express monad typeclass in Nim. I'd like to express that monad instance needs to have the flatMap procedure, like this:
proc flatMap[T, R](m: Monad[T], proc(x: T): Monad[R]): Monad[R]
The most obvious thing doesn't work:
type
Monad*[T] = concept m
# flatMap i.e. monadic bind
flatMap(m, proc(x: T): Monad[R]) is Monad[R]
# somewhere else
proc flatMap*[T; R](coll: Iterator[T], f: (proc(item: T): Iterator[R])): Iterator[R]
# and
terator[int] is Monad[int]
Error from --reportConceptFailures:on:
base.nim(18, 5) Error: type mismatch: got (Iterator[system.int], typedesc[proc (x: typedesc[int]): Monad[Error Type]{.closure.}])
but expected one of:
iterate.flatMap(coll: seq[T], f: proc (item: T): seq[R]{.closure.})
iterate.flatMap(coll: Iterator[flatMap.T], f: proc (item: T): Iterator[flatMap.R]{.closure.})
Do you have any ideas?
Well, I know its undefined, I've just hoped that undefined types will default to "unique type variable". Is it possible to make something like:
forall R: flatMap(m, proc(x: T): Monad[R]) is Monad[R]