# concepts

Theme:

- Index

Search:
Group by:
Source Edit

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

# Imports

ast, semdata, lookups, lineinfos, idents, msgs, renderer, types, layeredtable

# Types

    MatchFlags = enum
      mfDontBind, mfCheckGeneric

  Source Edit

# Procs

    proc conceptBody(n: PType): PNode {....raises: [], tags: [], forbids: [].}

  Source Edit

    proc conceptMatch(c: PContext; concpt, arg: PType; bindings: var LayeredIdTable;
                      invocation: PType; flags: set[MatchFlags] = {}): bool {.
        ...raises: [Exception, KeyError, ValueError, OSError],
        tags: [RootEffect, ReadDirEffect], 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 fulfill 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