New styled concepts for Nim. See https://github.com/nim-lang/RFCs/issues/168 for details. Note this is a first implementation and only the "Concept matching" section has been implemented.
Code dealing with Concept declarations
Concept matching
Procs
proc conceptMatch(c: PContext; concpt, arg: PType; bindings: var TIdTable; invocation: PType): bool {....raises: [KeyError, Exception], tags: [ReadDirEffect, RootEffect], forbids: [].}
- Entry point from sigmatch. 'concpt' is the concept we try to match (here still a PType but we extract its AST via 'concpt.n.lastSon'). 'arg' is the type that might fullfill the concept's requirements. If so, we return true and fill the 'bindings' with pairs of (typeVar, instance) pairs. ('typeVar' is usually simply written as a generic 'T'.) 'invocation' can be nil for atomic concepts. For non-atomic concepts, it contains the C[S, T] parent type that we look for. We need this because we need to store bindings for 'S' and 'T' inside 'bindings' on a successful match. It is very important that we do not add any bindings at all on an unsuccessful match! Source Edit
proc semConceptDeclaration(c: PContext; n: PNode): PNode {....raises: [KeyError, Exception, ValueError, OSError, IOError, ERecoverableError], tags: [ RootEffect, ReadDirEffect, WriteIOEffect, ReadIOEffect, ReadEnvEffect], forbids: [].}
- Semantic checking for the concept declaration. Runs when we process the concept itself, not its matching process. Source Edit