===
Anonymous functions
===

procedure Main;
begin
  a := 
    procedure
    begin
    end;

  b := 
    function(a,b:c): d
    begin
      Result := 42;
    end;

  c := 
    (
      function(a:b): b
      begin
        Result := a;
      end
    )(42);
end;

---

(root
  (defProc
    (declProc (kProcedure) (identifier))
    (block
      (kBegin)
      (assignment
        (identifier)
        (kAssign)
        (lambda (kProcedure)
          (block
            (kBegin)
            (kEnd))))
      (assignment
        (identifier)
        (kAssign)
        (lambda (kFunction)
          (declArgs
            (declArg
              (identifier)
              (identifier)
              (type (typeref (identifier)))))
          (typeref (identifier))
          (block
            (kBegin)
            (assignment (identifier) (kAssign) (literalNumber))
            (kEnd))))
      (assignment
        (identifier)
        (kAssign)
        (exprCall
          (exprParens
            (lambda (kFunction)
              (declArgs
                (declArg
                  (identifier)
                  (type (typeref (identifier)))))
              (typeref (identifier))
              (block
                (kBegin)
                (assignment (identifier) (kAssign) (identifier))
                (kEnd))))
          (exprArgs
            (literalNumber))))
      (kEnd))))


===
Reference to
===

type
  a = reference to procedure;
  a = reference to procedure(b, c: d);
  a = reference to function: b;
  a = reference to function(b: c): d;

---

(root
  (declTypes (kType)
    (declType (identifier) (kEq)
      (type
        (declProcRef (kReference) (kTo) (kProcedure))))
    (declType (identifier) (kEq)
      (type
        (declProcRef (kReference) (kTo) (kProcedure)
          (declArgs
            (declArg
              (identifier)
              (identifier)
              (type (typeref (identifier))))))))
    (declType (identifier) (kEq)
      (type
        (declProcRef (kReference) (kTo) (kFunction)
          (typeref (identifier)))))
    (declType (identifier) (kEq)
      (type
        (declProcRef (kReference) (kTo) (kFunction)
          (declArgs
            (declArg (identifier)
              (type (typeref (identifier)))))
          (typeref (identifier)))))))

