define what a subtree is as a property

define what a subtree is as a property

-- Modeling Opetopes
-- here is Eric's editor: http://sma.epfl.ch/~finster/opetope/opetope.html
--
-- Note: Kock et al. use a similar scheme, where
--          - dots    <-->   lines
--          - spheres <-->   dots
--          - lines disappear
--          -                spheres appear

-- Note: In Eric's new work (at IAS) there are no
--       dots any more, instead he uses 'outout cards', so
--          - (output) cards   <-->  lines
--          - space between stacked cards <--> output cards
--          - lines disappear
--          -                (regular) cards appear

import "../tests/NatList.prg"

-- list kind
--kind List = Ni | Co

-- define the Tree kind, a rose tree
-- note: Ni may only appear in Fork second position (TODO: use GADT!)

kind Tree = Unit | Ni | Fork Tree Tree deriving syntax (tr) List(Ni, Fork) Unit(Unit)

-- define a proposition for subtrees

prop Subtree :: Tree ~> Tree ~> * where
  BothUnit :: Subtree ()tr ()tr
  BothNil :: Subtree []tr []tr
  Take :: Subtree head head' -> Subtree tail tail' -> Subtree [head; tail]tr [head'; tail']tr
  Skip :: Subtree tail tail' -> Subtree [head; tail]tr [head'; tail']tr

--- OLD IMPLEMENTATION FOLLOWS

-- Node Types

kind NodeType = Regular | Universal

-- Node Labels (parametrized by dimension?)

data NodeLabel = Named (Label n)
               | Comp NodeLabel NodeLabel

-- Node: named faces as inputs and an output (face)

-- Consuming some twig

data Eat :: Twig ~> * where
  NoDot :: Eat None  -- do not extend till next sprouting point
  Sub :: Eat (Sprout l)

-- A connected deck of cards

data Deck :: Twig ~> Twig ~> * where
  Air :: Deck t None
  Card :: Eat t -> Deck subt out -> Deck t (Sprout [out]w)

-- A forest: trees in each dimension up to n
--   o when it ends in a corolla then it is a cell (n-dimensional)
--

--data Forest

-- Idea: each tree must have two type parameters
--       o left: set of nodes from dim (n - 1) is our (tree of) lines
--       o right: my set of nodes is the tree I push to dim n + 1

-- HAH! we have a thrist!

-- trees live at the type level

-- have these forms
--      O  |
--   o  |  o
--      o

--         |
-- List of o starts at O

data List :: *1 where
  No :: List
  Ext :: List ~> Twig ~> List
 deriving LeftList(w)

data Twig :: *1 where
  None :: Twig
  Sprout :: List ~> Twig

-- an Opetope is a LeftThrist of Decks

-- Dimension Zero is always:

dim0 = Card NoDot Air

dim1 = Card Sub Air

upto1 = [dim0, dim1]lt

-- Modeling Opetopes
-- here is Eric's editor: http://sma.epfl.ch/~finster/opetope/opetope.html
--
-- Note: Kock et al. use similar different scheme, where
--          - dots    <-->   lines
--          - spheres <-->   dots
--          - lines disappear
--          -                spheres appear

-- Note: In Eric's new work (at IAS) there are no
--       dots any more, instead he uses 'outout cards', so
--          - (output) cards   <-->  lines
--          - space between stacked cards <--> output cards
--          - lines disappear
--          -                (regular) cards appear

import "../tests/NatList.prg"

--- OLD IMPLEMENTATION FOLLOWS

-- Node Types

kind NodeType = Regular | Universal

-- Node Labels (parametrized by dimension?)

data NodeLabel = Named (Label n)
               | Comp NodeLabel NodeLabel

-- Node: named faces as inputs and an output (face)

-- Consuming some twig

data Eat :: Twig ~> * where
  NoDot :: Eat None  -- do not extend till next sprouting point
  Sub :: Eat (Sprout l)

-- A connected deck of cards

data Deck :: Twig ~> Twig ~> * where
  Air :: Deck t None
  Card :: Eat t -> Deck subt out -> Deck t (Sprout [out]w)

-- A forest: trees in each dimension up to n
--   o when it ends in a corolla then it is a cell (n-dimensional)
--

--data Forest

-- Idea: each tree must have two type parameters
--       o left: set of nodes from dim (n - 1) is our (tree of) lines
--       o right: my set of nodes is the tree I push to dim n + 1

-- HAH! we have a thrist!

-- trees live at the type level

-- have these forms
--      O  |
--   o  |  o
--      o

--         |
-- List of o starts at O

data List :: *1 where
  No :: List
  Ext :: List ~> Twig ~> List
 deriving LeftList(w)

data Twig :: *1 where
  None :: Twig
  Sprout :: List ~> Twig

-- an Opetope is a LeftThrist of Decks

-- Dimension Zero is always:

dim0 = Card NoDot Air

dim1 = Card Sub Air

upto1 = [dim0, dim1]lt


QtSerialPort: module updated

QtSerialPort: module updated

Modified:
source/QtSerialPort/QSerialPortInfo.prg

/*

  Qt5xHb - Bindings libraries for Harbour/xHarbour and Qt Framework 5

  Copyright (C) 2018 Marcos Antonio Gambeta <marcosgambeta AT outlook DOT com>

*/

/*
  DO NOT EDIT THIS FILE - the content was created using a source code generator
*/

#include "hbclass.ch"

CLASS QSerialPortInfo

   DATA pointer
   DATA self_destruction INIT .F.

   METHOD new
   METHOD delete
   METHOD swap
   METHOD portName
   METHOD systemLocation
   METHOD description
   METHOD manufacturer
   METHOD vendorIdentifier
   METHOD productIdentifier
   METHOD hasVendorIdentifier
   METHOD hasProductIdentifier
   METHOD isNull
   METHOD isBusy
   METHOD isValid
   METHOD standardBaudRates
   METHOD availablePorts

   METHOD newFrom
   METHOD newFromObject
   METHOD newFromPointer
   METHOD selfDestruction
   METHOD setSelfDestruction

   DESTRUCTOR destroyObject

END CLASS

PROCEDURE destroyObject () CLASS QSerialPortInfo
   IF ::self_destruction
      ::delete()
   ENDIF
RETURN

#pragma BEGINDUMP

#include <Qt>

#ifndef __XHARBOUR__
#if (QT_VERSION >= QT_VERSION_CHECK(5,1,0))
#include <QSerialPortInfo>
#endif
#endif

#include "qt5xhb_common.h"
#include "qt5xhb_macros.h"
#include "qt5xhb_utils.h"

#ifdef __XHARBOUR__
#if (QT_VERSION >= QT_VERSION_CHECK(5,1,0))
#include <QSerialPortInfo>
#endif
#endif

#include <QString>

/*
QSerialPortInfo()
*/
void QSerialPortInfo_new1 ()
{
#if (QT_VERSION >= QT_VERSION_CHECK(5,1,0))
  QSerialPortInfo * o = new QSerialPortInfo ();
  _qt5xhb_returnNewObject( o, true );
#endif
}

/*
QSerialPortInfo(const QSerialPort &port)
*/
void QSerialPortInfo_new2 ()
{
#if (QT_VERSION >= QT_VERSION_CHECK(5,1,0))
  QSerialPortInfo * o = new QSerialPortInfo ( *PQSERIALPORT(1) );
  _qt5xhb_returnNewObject( o, true );
#endif
}

/*
QSerialPortInfo(const QString &name)
*/
void QSerialPortInfo_new3 ()
{
#if (QT_VERSION >= QT_VERSION_CHECK(5,1,0))
  QSerialPortInfo * o = new QSerialPortInfo ( PQSTRING(1) );
  _qt5xhb_returnNewObject( o, true );
#endif
}

/*
QSerialPortInfo(const QSerialPortInfo &other)
*/
void QSerialPortInfo_new4 ()
{
#if (QT_VERSION >= QT_VERSION_CHECK(5,1,0))
  QSerialPortInfo * o = new QSerialPortInfo ( *PQSERIALPORTINFO(1) );
  _qt5xhb_returnNewObject( o, true );
#endif
}

//[1]QSerialPortInfo()
//[2]QSerialPortInfo(const QSerialPort &port)
//[3]QSerialPortInfo(const QString &name)
//[4]QSerialPortInfo(const QSerialPortInfo &other)

HB_FUNC_STATIC( QSERIALPORTINFO_NEW )
{
#if (QT_VERSION >= QT_VERSION_CHECK(5,1,0))
  if( ISNUMPAR(0) )
  {
    QSerialPortInfo_new1();
  }
  else if( ISNUMPAR(1) && ISQSERIALPORT(1) )
  {
    QSerialPortInfo_new2();
  }
  else if( ISNUMPAR(1) && ISCHAR(1) )
  {
    QSerialPortInfo_new3();
  }
  else if( ISNUMPAR(1) && ISQSERIALPORTINFO(1) )
  {
    QSerialPortInfo_new4();
  }
  else
  {
    hb_errRT_BASE( EG_ARG, 3012, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
  }
#endif
}

HB_FUNC_STATIC( QSERIALPORTINFO_DELETE )
{
#if (QT_VERSION >= QT_VERSION_CHECK(5,1,0))
  QSerialPortInfo * obj = (QSerialPortInfo *) _qt5xhb_itemGetPtrStackSelfItem();

  if( obj )
  {
    delete obj;
    obj = NULL;
    PHB_ITEM self = hb_stackSelfItem();
    PHB_ITEM ptr = hb_itemPutPtr( NULL, NULL );
    hb_objSendMsg( self, "_pointer", 1, ptr );
    hb_itemRelease( ptr );
  }

  hb_itemReturn( hb_stackSelfItem() );
#endif
}

/*
void swap(QSerialPortInfo &other)
*/
HB_FUNC_STATIC( QSERIALPORTINFO_SWAP )
{
#if (QT_VERSION >= QT_VERSION_CHECK(5,1,0))
  QSerialPortInfo * obj = (QSerialPortInfo *) _qt5xhb_itemGetPtrStackSelfItem();

  if( obj )
  {
    if( ISNUMPAR(1) && ISQSERIALPORTINFO(1) )
    {
      obj->swap ( *PQSERIALPORTINFO(1) );
    }
    else
    {
      hb_errRT_BASE( EG_ARG, 3012, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
    }
  }

  hb_itemReturn( hb_stackSelfItem() );
#endif
}

/*
QString portName() const
*/
HB_FUNC_STATIC( QSERIALPORTINFO_PORTNAME )
{
#if (QT_VERSION >= QT_VERSION_CHECK(5,1,0))
  QSerialPortInfo * obj = (QSerialPortInfo *) _qt5xhb_itemGetPtrStackSelfItem();

  if( obj )
  {
    if( ISNUMPAR(0) )
    {
      RQSTRING( obj->portName () );
    }
    else
    {
      hb_errRT_BASE( EG_ARG, 3012, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
    }
  }
#endif
}

/*
QString systemLocation() const
*/
HB_FUNC_STATIC( QSERIALPORTINFO_SYSTEMLOCATION )
{
#if (QT_VERSION >= QT_VERSION_CHECK(5,1,0))
  QSerialPortInfo * obj = (QSerialPortInfo *) _qt5xhb_itemGetPtrStackSelfItem();

  if( obj )
  {
    if( ISNUMPAR(0) )
    {
      RQSTRING( obj->systemLocation () );
    }
    else
    {
      hb_errRT_BASE( EG_ARG, 3012, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
    }
  }
#endif
}

/*
QString description() const
*/
HB_FUNC_STATIC( QSERIALPORTINFO_DESCRIPTION )
{
#if (QT_VERSION >= QT_VERSION_CHECK(5,1,0))
  QSerialPortInfo * obj = (QSerialPortInfo *) _qt5xhb_itemGetPtrStackSelfItem();

  if( obj )
  {
    if( ISNUMPAR(0) )
    {
      RQSTRING( obj->description () );
    }
    else
    {
      hb_errRT_BASE( EG_ARG, 3012, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
    }
  }
#endif
}

/*
QString manufacturer() const
*/
HB_FUNC_STATIC( QSERIALPORTINFO_MANUFACTURER )
{
#if (QT_VERSION >= QT_VERSION_CHECK(5,1,0))
  QSerialPortInfo * obj = (QSerialPortInfo *) _qt5xhb_itemGetPtrStackSelfItem();

  if( obj )
  {
    if( ISNUMPAR(0) )
    {
      RQSTRING( obj->manufacturer () );
    }
    else
    {
      hb_errRT_BASE( EG_ARG, 3012, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
    }
  }
#endif
}

/*
quint16 vendorIdentifier() const
*/
HB_FUNC_STATIC( QSERIALPORTINFO_VENDORIDENTIFIER )
{
#if (QT_VERSION >= QT_VERSION_CHECK(5,1,0))
  QSerialPortInfo * obj = (QSerialPortInfo *) _qt5xhb_itemGetPtrStackSelfItem();

  if( obj )
  {
    if( ISNUMPAR(0) )
    {
      RQUINT16( obj->vendorIdentifier () );
    }
    else
    {
      hb_errRT_BASE( EG_ARG, 3012, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
    }
  }
#endif
}

/*
quint16 productIdentifier() const
*/
HB_FUNC_STATIC( QSERIALPORTINFO_PRODUCTIDENTIFIER )
{
#if (QT_VERSION >= QT_VERSION_CHECK(5,1,0))
  QSerialPortInfo * obj = (QSerialPortInfo *) _qt5xhb_itemGetPtrStackSelfItem();

  if( obj )
  {
    if( ISNUMPAR(0) )
    {
      RQUINT16( obj->productIdentifier () );
    }
    else
    {
      hb_errRT_BASE( EG_ARG, 3012, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
    }
  }
#endif
}

/*
bool hasVendorIdentifier() const
*/
HB_FUNC_STATIC( QSERIALPORTINFO_HASVENDORIDENTIFIER )
{
#if (QT_VERSION >= QT_VERSION_CHECK(5,1,0))
  QSerialPortInfo * obj = (QSerialPortInfo *) _qt5xhb_itemGetPtrStackSelfItem();

  if( obj )
  {
    if( ISNUMPAR(0) )
    {
      RBOOL( obj->hasVendorIdentifier () );
    }
    else
    {
      hb_errRT_BASE( EG_ARG, 3012, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
    }
  }
#endif
}

/*
bool hasProductIdentifier() const
*/
HB_FUNC_STATIC( QSERIALPORTINFO_HASPRODUCTIDENTIFIER )
{
#if (QT_VERSION >= QT_VERSION_CHECK(5,1,0))
  QSerialPortInfo * obj = (QSerialPortInfo *) _qt5xhb_itemGetPtrStackSelfItem();

  if( obj )
  {
    if( ISNUMPAR(0) )
    {
      RBOOL( obj->hasProductIdentifier () );
    }
    else
    {
      hb_errRT_BASE( EG_ARG, 3012, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
    }
  }
#endif
}

/*
bool isNull() const
*/
HB_FUNC_STATIC( QSERIALPORTINFO_ISNULL )
{
#if (QT_VERSION >= QT_VERSION_CHECK(5,1,0))
  QSerialPortInfo * obj = (QSerialPortInfo *) _qt5xhb_itemGetPtrStackSelfItem();

  if( obj )
  {
    if( ISNUMPAR(0) )
    {
      RBOOL( obj->isNull () );
    }
    else
    {
      hb_errRT_BASE( EG_ARG, 3012, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
    }
  }
#endif
}

/*
bool isBusy() const
*/
HB_FUNC_STATIC( QSERIALPORTINFO_ISBUSY )
{
#if (QT_VERSION >= QT_VERSION_CHECK(5,1,0))
  QSerialPortInfo * obj = (QSerialPortInfo *) _qt5xhb_itemGetPtrStackSelfItem();

  if( obj )
  {
    if( ISNUMPAR(0) )
    {
      RBOOL( obj->isBusy () );
    }
    else
    {
      hb_errRT_BASE( EG_ARG, 3012, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
    }
  }
#endif
}

/*
bool isValid() const
*/
HB_FUNC_STATIC( QSERIALPORTINFO_ISVALID )
{
#if (QT_VERSION >= QT_VERSION_CHECK(5,1,0))
  QSerialPortInfo * obj = (QSerialPortInfo *) _qt5xhb_itemGetPtrStackSelfItem();

  if( obj )
  {
    if( ISNUMPAR(0) )
    {
      RBOOL( obj->isValid () );
    }
    else
    {
      hb_errRT_BASE( EG_ARG, 3012, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
    }
  }
#endif
}

/*
static QList<qint32> standardBaudRates()
*/
HB_FUNC_STATIC( QSERIALPORTINFO_STANDARDBAUDRATES )
{
#if (QT_VERSION >= QT_VERSION_CHECK(5,1,0))
    if( ISNUMPAR(0) )
  {
      QList<qint32> list = QSerialPortInfo::standardBaudRates ();
      _qt5xhb_convert_qlist_qint32_to_array ( list );
  }
  else
  {
    hb_errRT_BASE( EG_ARG, 3012, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
  }
#endif
}

/*
static QList<QSerialPortInfo> availablePorts()
*/
HB_FUNC_STATIC( QSERIALPORTINFO_AVAILABLEPORTS )
{
#if (QT_VERSION >= QT_VERSION_CHECK(5,1,0))
    if( ISNUMPAR(0) )
  {
      QList<QSerialPortInfo> list = QSerialPortInfo::availablePorts ();
      PHB_DYNS pDynSym = hb_dynsymFindName( "QSERIALPORTINFO" );
      PHB_ITEM pArray = hb_itemArrayNew(0);
      int i;
      for(i=0;i<list.count();i++)
      {
        if( pDynSym )
        {
          hb_vmPushDynSym( pDynSym );
          hb_vmPushNil();
          hb_vmDo( 0 );
          PHB_ITEM pObject = hb_itemNew( NULL );
          hb_itemCopy( pObject, hb_stackReturnItem() );
          PHB_ITEM pItem = hb_itemNew( NULL );
          hb_itemPutPtr( pItem, (QSerialPortInfo *) new QSerialPortInfo ( list[i] ) );
          hb_objSendMsg( pObject, "_POINTER", 1, pItem );
          hb_itemRelease( pItem );
          PHB_ITEM pDestroy = hb_itemNew( NULL );
          hb_itemPutL( pDestroy, true );
          hb_objSendMsg( pObject, "_SELF_DESTRUCTION", 1, pDestroy );
          hb_itemRelease( pDestroy );
          hb_arrayAddForward( pArray, pObject );
          hb_itemRelease( pObject );
        }
        else
        {
          hb_errRT_BASE( EG_NOFUNC, 1001, NULL, "QSERIALPORTINFO", HB_ERR_ARGS_BASEPARAMS );
        }
      }
      hb_itemReturnRelease(pArray);
  }
  else
  {
    hb_errRT_BASE( EG_ARG, 3012, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
  }
#endif
}

HB_FUNC_STATIC( QSERIALPORTINFO_NEWFROM )
{
  PHB_ITEM self = hb_stackSelfItem();

  if( hb_pcount() == 1 && ISOBJECT(1) )
  {
    PHB_ITEM ptr = hb_itemPutPtr( NULL, (void *) hb_itemGetPtr( hb_objSendMsg( hb_param(1, HB_IT_OBJECT ), "POINTER", 0 ) ) );
    hb_objSendMsg( self, "_pointer", 1, ptr );
    hb_itemRelease( ptr );
    PHB_ITEM des = hb_itemPutL( NULL, false );
    hb_objSendMsg( self, "_self_destruction", 1, des );
    hb_itemRelease( des );
  }
  else if( hb_pcount() == 1 && ISPOINTER(1) )
  {
    PHB_ITEM ptr = hb_itemPutPtr( NULL, (void *) hb_itemGetPtr( hb_param(1, HB_IT_POINTER ) ) );
    hb_objSendMsg( self, "_pointer", 1, ptr );
    hb_itemRelease( ptr );
    PHB_ITEM des = hb_itemPutL( NULL, false );
    hb_objSendMsg( self, "_self_destruction", 1, des );
    hb_itemRelease( des );
  }
  else
  {
    hb_errRT_BASE( EG_ARG, 3012, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
  }

  hb_itemReturn( self );
}

HB_FUNC_STATIC( QSERIALPORTINFO_NEWFROMOBJECT )
{
  HB_FUNC_EXEC( QSERIALPORTINFO_NEWFROM );
}

HB_FUNC_STATIC( QSERIALPORTINFO_NEWFROMPOINTER )
{
  HB_FUNC_EXEC( QSERIALPORTINFO_NEWFROM );
}

HB_FUNC_STATIC( QSERIALPORTINFO_SELFDESTRUCTION )
{
  hb_retl( (bool) hb_itemGetL( hb_objSendMsg( hb_stackSelfItem(), "SELF_DESTRUCTION", 0 ) ) );
}

HB_FUNC_STATIC( QSERIALPORTINFO_SETSELFDESTRUCTION )
{
  PHB_ITEM self = hb_stackSelfItem();

  if( hb_pcount() == 1 && ISLOG(1) )
  {
    PHB_ITEM des = hb_itemPutL( NULL, hb_parl(1) );
    hb_objSendMsg( self, "_self_destruction", 1, des );
    hb_itemRelease( des );
  }
  else
  {
    hb_errRT_BASE( EG_ARG, 3012, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
  }

  hb_itemReturn( self );
}

#pragma ENDDUMP

/*

  Qt5xHb - Bindings libraries for Harbour/xHarbour and Qt Framework 5

  Copyright (C) 2018 Marcos Antonio Gambeta <marcosgambeta AT outlook DOT com>

*/

/*
  DO NOT EDIT THIS FILE - the content was created using a source code generator
*/

#include "hbclass.ch"

CLASS QSerialPortInfo

   DATA pointer
   DATA self_destruction INIT .F.

   METHOD new
   METHOD delete
   METHOD swap
   METHOD portName
   METHOD systemLocation
   METHOD description
   METHOD manufacturer
   METHOD vendorIdentifier
   METHOD productIdentifier
   METHOD hasVendorIdentifier
   METHOD hasProductIdentifier
   METHOD isNull
   METHOD isBusy
   METHOD isValid
   METHOD standardBaudRates
   METHOD availablePorts

   METHOD newFrom
   METHOD newFromObject
   METHOD newFromPointer
   METHOD selfDestruction
   METHOD setSelfDestruction

   DESTRUCTOR destroyObject

END CLASS

PROCEDURE destroyObject () CLASS QSerialPortInfo
   IF ::self_destruction
      ::delete()
   ENDIF
RETURN

#pragma BEGINDUMP

#include <Qt>

#ifndef __XHARBOUR__
#if (QT_VERSION >= QT_VERSION_CHECK(5,1,0))
#include <QSerialPortInfo>
#endif
#endif

#include "qt5xhb_common.h"
#include "qt5xhb_macros.h"
#include "qt5xhb_utils.h"

#ifdef __XHARBOUR__
#if (QT_VERSION >= QT_VERSION_CHECK(5,1,0))
#include <QSerialPortInfo>
#endif
#endif

#include <QString>

/*
QSerialPortInfo()
*/
void QSerialPortInfo_new1 ()
{
#if (QT_VERSION >= QT_VERSION_CHECK(5,1,0))
  QSerialPortInfo * o = new QSerialPortInfo ();
  _qt5xhb_returnNewObject( o, true );
#endif
}

/*
QSerialPortInfo(const QSerialPort &port)
*/
void QSerialPortInfo_new2 ()
{
#if (QT_VERSION >= QT_VERSION_CHECK(5,1,0))
  QSerialPortInfo * o = new QSerialPortInfo ( *PQSERIALPORT(1) );
  _qt5xhb_returnNewObject( o, true );
#endif
}

/*
QSerialPortInfo(const QString &name)
*/
void QSerialPortInfo_new3 ()
{
#if (QT_VERSION >= QT_VERSION_CHECK(5,1,0))
  QSerialPortInfo * o = new QSerialPortInfo ( PQSTRING(1) );
  _qt5xhb_returnNewObject( o, true );
#endif
}

/*
QSerialPortInfo(const QSerialPortInfo &other)
*/
void QSerialPortInfo_new4 ()
{
#if (QT_VERSION >= QT_VERSION_CHECK(5,1,0))
  QSerialPortInfo * o = new QSerialPortInfo ( *PQSERIALPORTINFO(1) );
  _qt5xhb_returnNewObject( o, true );
#endif
}

//[1]QSerialPortInfo()
//[2]QSerialPortInfo(const QSerialPort &port)
//[3]QSerialPortInfo(const QString &name)
//[4]QSerialPortInfo(const QSerialPortInfo &other)

HB_FUNC_STATIC( QSERIALPORTINFO_NEW )
{
#if (QT_VERSION >= QT_VERSION_CHECK(5,1,0))
  if( ISNUMPAR(0) )
  {
    QSerialPortInfo_new1();
  }
  else if( ISNUMPAR(1) && ISQSERIALPORT(1) )
  {
    QSerialPortInfo_new2();
  }
  else if( ISNUMPAR(1) && ISCHAR(1) )
  {
    QSerialPortInfo_new3();
  }
  else if( ISNUMPAR(1) && ISQSERIALPORTINFO(1) )
  {
    QSerialPortInfo_new4();
  }
  else
  {
    hb_errRT_BASE( EG_ARG, 3012, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
  }
#endif
}

HB_FUNC_STATIC( QSERIALPORTINFO_DELETE )
{
#if (QT_VERSION >= QT_VERSION_CHECK(5,1,0))
  QSerialPortInfo * obj = (QSerialPortInfo *) _qt5xhb_itemGetPtrStackSelfItem();

  if( obj )
  {
    delete obj;
    obj = NULL;
    PHB_ITEM self = hb_stackSelfItem();
    PHB_ITEM ptr = hb_itemPutPtr( NULL, NULL );
    hb_objSendMsg( self, "_pointer", 1, ptr );
    hb_itemRelease( ptr );
  }

  hb_itemReturn( hb_stackSelfItem() );
#endif
}

/*
void swap(QSerialPortInfo &other)
*/
HB_FUNC_STATIC( QSERIALPORTINFO_SWAP )
{
#if (QT_VERSION >= QT_VERSION_CHECK(5,1,0))
  QSerialPortInfo * obj = (QSerialPortInfo *) _qt5xhb_itemGetPtrStackSelfItem();

  if( obj )
  {
    if( ISNUMPAR(1) && ISQSERIALPORTINFO(1) )
    {
      obj->swap ( *PQSERIALPORTINFO(1) );
    }
    else
    {
      hb_errRT_BASE( EG_ARG, 3012, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
    }
  }

  hb_itemReturn( hb_stackSelfItem() );
#endif
}

/*
QString portName() const
*/
HB_FUNC_STATIC( QSERIALPORTINFO_PORTNAME )
{
#if (QT_VERSION >= QT_VERSION_CHECK(5,1,0))
  QSerialPortInfo * obj = (QSerialPortInfo *) _qt5xhb_itemGetPtrStackSelfItem();

  if( obj )
  {
    if( ISNUMPAR(0) )
    {
      RQSTRING( obj->portName () );
    }
    else
    {
      hb_errRT_BASE( EG_ARG, 3012, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
    }
  }
#endif
}

/*
QString systemLocation() const
*/
HB_FUNC_STATIC( QSERIALPORTINFO_SYSTEMLOCATION )
{
#if (QT_VERSION >= QT_VERSION_CHECK(5,1,0))
  QSerialPortInfo * obj = (QSerialPortInfo *) _qt5xhb_itemGetPtrStackSelfItem();

  if( obj )
  {
    if( ISNUMPAR(0) )
    {
      RQSTRING( obj->systemLocation () );
    }
    else
    {
      hb_errRT_BASE( EG_ARG, 3012, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
    }
  }
#endif
}

/*
QString description() const
*/
HB_FUNC_STATIC( QSERIALPORTINFO_DESCRIPTION )
{
#if (QT_VERSION >= QT_VERSION_CHECK(5,1,0))
  QSerialPortInfo * obj = (QSerialPortInfo *) _qt5xhb_itemGetPtrStackSelfItem();

  if( obj )
  {
    if( ISNUMPAR(0) )
    {
      RQSTRING( obj->description () );
    }
    else
    {
      hb_errRT_BASE( EG_ARG, 3012, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
    }
  }
#endif
}

/*
QString manufacturer() const
*/
HB_FUNC_STATIC( QSERIALPORTINFO_MANUFACTURER )
{
#if (QT_VERSION >= QT_VERSION_CHECK(5,1,0))
  QSerialPortInfo * obj = (QSerialPortInfo *) _qt5xhb_itemGetPtrStackSelfItem();

  if( obj )
  {
    if( ISNUMPAR(0) )
    {
      RQSTRING( obj->manufacturer () );
    }
    else
    {
      hb_errRT_BASE( EG_ARG, 3012, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
    }
  }
#endif
}

/*
quint16 vendorIdentifier() const
*/
HB_FUNC_STATIC( QSERIALPORTINFO_VENDORIDENTIFIER )
{
#if (QT_VERSION >= QT_VERSION_CHECK(5,1,0))
  QSerialPortInfo * obj = (QSerialPortInfo *) _qt5xhb_itemGetPtrStackSelfItem();

  if( obj )
  {
    if( ISNUMPAR(0) )
    {
      RQUINT16( obj->vendorIdentifier () );
    }
    else
    {
      hb_errRT_BASE( EG_ARG, 3012, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
    }
  }
#endif
}

/*
quint16 productIdentifier() const
*/
HB_FUNC_STATIC( QSERIALPORTINFO_PRODUCTIDENTIFIER )
{
#if (QT_VERSION >= QT_VERSION_CHECK(5,1,0))
  QSerialPortInfo * obj = (QSerialPortInfo *) _qt5xhb_itemGetPtrStackSelfItem();

  if( obj )
  {
    if( ISNUMPAR(0) )
    {
      RQUINT16( obj->productIdentifier () );
    }
    else
    {
      hb_errRT_BASE( EG_ARG, 3012, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
    }
  }
#endif
}

/*
bool hasVendorIdentifier() const
*/
HB_FUNC_STATIC( QSERIALPORTINFO_HASVENDORIDENTIFIER )
{
#if (QT_VERSION >= QT_VERSION_CHECK(5,1,0))
  QSerialPortInfo * obj = (QSerialPortInfo *) _qt5xhb_itemGetPtrStackSelfItem();

  if( obj )
  {
    if( ISNUMPAR(0) )
    {
      RBOOL( obj->hasVendorIdentifier () );
    }
    else
    {
      hb_errRT_BASE( EG_ARG, 3012, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
    }
  }
#endif
}

/*
bool hasProductIdentifier() const
*/
HB_FUNC_STATIC( QSERIALPORTINFO_HASPRODUCTIDENTIFIER )
{
#if (QT_VERSION >= QT_VERSION_CHECK(5,1,0))
  QSerialPortInfo * obj = (QSerialPortInfo *) _qt5xhb_itemGetPtrStackSelfItem();

  if( obj )
  {
    if( ISNUMPAR(0) )
    {
      RBOOL( obj->hasProductIdentifier () );
    }
    else
    {
      hb_errRT_BASE( EG_ARG, 3012, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
    }
  }
#endif
}

/*
bool isNull() const
*/
HB_FUNC_STATIC( QSERIALPORTINFO_ISNULL )
{
#if (QT_VERSION >= QT_VERSION_CHECK(5,1,0))
  QSerialPortInfo * obj = (QSerialPortInfo *) _qt5xhb_itemGetPtrStackSelfItem();

  if( obj )
  {
    if( ISNUMPAR(0) )
    {
      RBOOL( obj->isNull () );
    }
    else
    {
      hb_errRT_BASE( EG_ARG, 3012, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
    }
  }
#endif
}

/*
bool isBusy() const
*/
HB_FUNC_STATIC( QSERIALPORTINFO_ISBUSY )
{
#if (QT_VERSION >= QT_VERSION_CHECK(5,1,0))
  QSerialPortInfo * obj = (QSerialPortInfo *) _qt5xhb_itemGetPtrStackSelfItem();

  if( obj )
  {
    if( ISNUMPAR(0) )
    {
      RBOOL( obj->isBusy () );
    }
    else
    {
      hb_errRT_BASE( EG_ARG, 3012, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
    }
  }
#endif
}

/*
bool isValid() const
*/
HB_FUNC_STATIC( QSERIALPORTINFO_ISVALID )
{
#if (QT_VERSION >= QT_VERSION_CHECK(5,1,0))
  QSerialPortInfo * obj = (QSerialPortInfo *) _qt5xhb_itemGetPtrStackSelfItem();

  if( obj )
  {
    if( ISNUMPAR(0) )
    {
      RBOOL( obj->isValid () );
    }
    else
    {
      hb_errRT_BASE( EG_ARG, 3012, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
    }
  }
#endif
}

/*
static QList<qint32> standardBaudRates()
*/
HB_FUNC_STATIC( QSERIALPORTINFO_STANDARDBAUDRATES )
{
#if (QT_VERSION >= QT_VERSION_CHECK(5,1,0))
  QList<qint32> list = QSerialPortInfo::standardBaudRates ();
  _qt5xhb_convert_qlist_qint32_to_array ( list );
#endif
}

/*
static QList<QSerialPortInfo> availablePorts()
*/
HB_FUNC_STATIC( QSERIALPORTINFO_AVAILABLEPORTS )
{
#if (QT_VERSION >= QT_VERSION_CHECK(5,1,0))
  QList<QSerialPortInfo> list = QSerialPortInfo::availablePorts ();
  PHB_DYNS pDynSym = hb_dynsymFindName( "QSERIALPORTINFO" );
  PHB_ITEM pArray = hb_itemArrayNew(0);
  int i;
  for(i=0;i<list.count();i++)
  {
    if( pDynSym )
    {
      hb_vmPushDynSym( pDynSym );
      hb_vmPushNil();
      hb_vmDo( 0 );
      PHB_ITEM pObject = hb_itemNew( NULL );
      hb_itemCopy( pObject, hb_stackReturnItem() );
      PHB_ITEM pItem = hb_itemNew( NULL );
      hb_itemPutPtr( pItem, (QSerialPortInfo *) new QSerialPortInfo ( list[i] ) );
      hb_objSendMsg( pObject, "_POINTER", 1, pItem );
      hb_itemRelease( pItem );
      PHB_ITEM pDestroy = hb_itemNew( NULL );
      hb_itemPutL( pDestroy, true );
      hb_objSendMsg( pObject, "_SELF_DESTRUCTION", 1, pDestroy );
      hb_itemRelease( pDestroy );
      hb_arrayAddForward( pArray, pObject );
      hb_itemRelease( pObject );
    }
  }
  hb_itemReturnRelease(pArray);
#endif
}

HB_FUNC_STATIC( QSERIALPORTINFO_NEWFROM )
{
  PHB_ITEM self = hb_stackSelfItem();

  if( hb_pcount() == 1 && ISOBJECT(1) )
  {
    PHB_ITEM ptr = hb_itemPutPtr( NULL, (void *) hb_itemGetPtr( hb_objSendMsg( hb_param(1, HB_IT_OBJECT ), "POINTER", 0 ) ) );
    hb_objSendMsg( self, "_pointer", 1, ptr );
    hb_itemRelease( ptr );
    PHB_ITEM des = hb_itemPutL( NULL, false );
    hb_objSendMsg( self, "_self_destruction", 1, des );
    hb_itemRelease( des );
  }
  else if( hb_pcount() == 1 && ISPOINTER(1) )
  {
    PHB_ITEM ptr = hb_itemPutPtr( NULL, (void *) hb_itemGetPtr( hb_param(1, HB_IT_POINTER ) ) );
    hb_objSendMsg( self, "_pointer", 1, ptr );
    hb_itemRelease( ptr );
    PHB_ITEM des = hb_itemPutL( NULL, false );
    hb_objSendMsg( self, "_self_destruction", 1, des );
    hb_itemRelease( des );
  }
  else
  {
    hb_errRT_BASE( EG_ARG, 3012, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
  }

  hb_itemReturn( self );
}

HB_FUNC_STATIC( QSERIALPORTINFO_NEWFROMOBJECT )
{
  HB_FUNC_EXEC( QSERIALPORTINFO_NEWFROM );
}

HB_FUNC_STATIC( QSERIALPORTINFO_NEWFROMPOINTER )
{
  HB_FUNC_EXEC( QSERIALPORTINFO_NEWFROM );
}

HB_FUNC_STATIC( QSERIALPORTINFO_SELFDESTRUCTION )
{
  hb_retl( (bool) hb_itemGetL( hb_objSendMsg( hb_stackSelfItem(), "SELF_DESTRUCTION", 0 ) ) );
}

HB_FUNC_STATIC( QSERIALPORTINFO_SETSELFDESTRUCTION )
{
  PHB_ITEM self = hb_stackSelfItem();

  if( hb_pcount() == 1 && ISLOG(1) )
  {
    PHB_ITEM des = hb_itemPutL( NULL, hb_parl(1) );
    hb_objSendMsg( self, "_self_destruction", 1, des );
    hb_itemRelease( des );
  }
  else
  {
    hb_errRT_BASE( EG_ARG, 3012, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
  }

  hb_itemReturn( self );
}

#pragma ENDDUMP


[runtime] removed typo

[runtime] removed typo

//
// Copyright (c) XSharp B.V.  All Rights Reserved.
// Licensed under the Apache License, Version 2.0.
// See License.txt in the project root for license information.
//
using System.Collections
using System.Collections.Generic
using System.Linq

BEGIN NAMESPACE Vulcan
	PUBLIC SEALED CLASS __Array IMPLEMENTS IEnumerable<Usual>
		private internalList as List<Usual>
		#region constructors
		CONSTRUCTOR()
			internalList := List<Usual>{}
		return

		CONSTRUCTOR(capacity as int)
			internalList := List<Usual>{capacity}
			internalList:AddRange(Enumerable.Repeat(nil,capacity))
		return

		CONSTRUCTOR( collection as IEnumerable<Usual>)
			internalList := List<Usual>{collection}
		return

		CONSTRUCTOR( elements as object[] )
		    self()
			if elements == null
				throw ArgumentNullException{nameof(elements)}
			endif
			foreach element as object in elements
				internallist:Add(Usual{element})
			next
		return

		constructor( elements as Usual[] )
			internallist := List<Usual>{elements}
		return
		#endregion
		#region properties
		public Property IsEmpty as logic
			get
				return (internallist:Count == 0)
			end get
		end property

		public Property Length as dword
			get
				return (dword)internallist:Count
			end get
		end property
		#endregion
		#region helper functions
		public method Add(u as Usual) as void
			internallist:Add(u)
		return
		#endregion
		public method GetEnumerator() as IEnumerator<Usual>
		return internallist:GetEnumerator()

		public method IEnumerable.GetEnumerator() as IEnumerator
		return internallist:GetEnumerator()
		public static method ArrayNew( dimensions params int[] ) as __Array
			local newArray as __Array
			if dimensions:Length != 0
			   newArray := ArrayNewHelper(dimensions,1)
			else
			   newArray := __Array{}
			endif
		return newArray

		public static method ArrayNewHelper(dimensions as int[], currentDim as int) as __Array
			local capacity := dimensions[currentDim-1] as int // one based ?
			local newArray := __Array{capacity} as __Array

			if currentDim != dimensions:Length
			  local nextDim := currentDim+1 as int
			  local index   := 1 as int
			  do while index <= capacity
			     newArray:Add(Usual{ArrayNewHelper(dimensions,nextDim)})
				 index+=1
			  enddo
			  return newArray
			endif
			local i as int
			for i:=1 upto capacity
				newArray:Add(Usual{})
			next
		return newArray

		public method Clone() as __Array
			throw NotImplementedException{"__Array.Clone is not implemented yet."}

		public method CloneShallow() as __Array
			throw NotImplementedException{"__Array.CloneShallow is not implemented yet."}

        ///
        /// <Summary>Access the array element using ZERO based array index</Summary>
        ///
		public method __GetElement(index params int[]) as Usual
			local indexLength := index:Length as int
			local currentArray := self as __Array
			local i as int

			for i:=0+__ARRAYBASE__  upto indexLength-2+__ARRAYBASE__
				local u := currentArray:internalList[ index[i]-__ARRAYBASE__] as Usual
				if u:IsNil
				   return nil
				endif
				if u:UsualType != UsualDataType.ARRAY
				   throw InvalidOperationException{"out of range error."}
				endif
				currentArray := (__Array) u
			next
			return currentArray:internalList[ index[i]-__ARRAYBASE__]

		public method Insert(index as dword,o as object) as void
			internallist:Insert((int)index-__ARRAYBASE__ ,Usual{o})
		return

		public method Insert(index as dword,u as Usual) as void
			internallist:Insert((int)index-__ARRAYBASE__ ,u)
		return

		public method Insert(position as dword) as __Array
			self:Insert(position,nil)
		return self

		public method RemoveAt(index as dword , count as int) as void
			internallist:RemoveRange((int)index-__ARRAYBASE__ ,count)
		return

		public method RemoveAt(index as dword) as void
			internallist:RemoveRange((int)index-__ARRAYBASE__,1 )
		return

		public method Resize(newSize as dword) as void
			local count := self:Length as dword
			if newSize == 0
			   internallist:Clear()
			else
				if newSize <= count
				   internallist:RemoveRange((int)newSize, (int)(count - newSize))
				else
				   count+=1
				   do while count <= newSize
					   local u := Usual{} as Usual
					   internallist:Add(u)
					   count++
			       enddo
				endif
			endif
		return

		public method ToString() as string
		return string.Format("{{[{0}]}}",internallist:Count)

		public method Sort(startIndex as int, count as int, comparer as IComparer<Usual>) as void
			internallist:Sort(startIndex-__ARRAYBASE__ ,count,comparer)
		return

		public method Size(size as dword) as __Array
			if size < 0
			   throw ArgumentException{"Size must be greate or equal zero."}
			endif
			if size > self:Length
			   local i as int
			   for i:=1-__ARRAYBASE__  upto size-__ARRAYBASE__
				   self:Add(Usual{})
			   next
			else
			   do while self:Length > size
			      self:RemoveAt(self:Length)
			   enddo
			endif
	    return self

		public Method Swap(position as dword, element as Usual)
			local original := internallist[(int) position - __ARRAYBASE__] as Usual
			internallist[(int) position - __ARRAYBASE__]:=element
		return original

		public Method __SetElement(u as Usual,index as int)
			internalList[index]:=u
		return u

		public Method __SetElement(u as Usual, index params int[] ) as Usual
			// indices are 0 based
			local length := index:Length as int
			local currentArray := self as __Array
			local i := 1 as int

			do while i <= length-__ARRAYBASE__
			   local uArray := internalList[index[i - __ARRAYBASE__ ]] as Usual
			   if !(uArray:UsualType == UsualDataType.ARRAY)
				  throw InvalidOperationException{"Out of range error."}
			   endif
			   currentArray := (__Array)uArray
			   i += 1
			enddo
			currentArray:internalList[index[i-1]] := u
		return u

		public Property self[index as dword] as Usual
			get
				VAR i := (int) index
				if i<__ARRAYBASE__ || i > System.Int32.MaxValue
					throw ArgumentOutOfRangeException{}
				endif
				return internalList[i - __ARRAYBASE__ ]
			end get
			set
				VAR i := (int) index
				if i<__ARRAYBASE__|| i > System.Int32.MaxValue
					throw ArgumentOutOfRangeException{}
				endif
				internalList[i-__ARRAYBASE__] := value
			end set
		end property

		public Property self[i as int] as Usual
			get
				if i<__ARRAYBASE__ || i > System.Int32.MaxValue
					throw ArgumentOutOfRangeException{}
				endif
				return internalList[i - __ARRAYBASE__ ]
			end get
			set
				if i<__ARRAYBASE__|| i > System.Int32.MaxValue
					throw ArgumentOutOfRangeException{}
				endif
				internalList[i-__ARRAYBASE__] := value
			end set
		end property

		public method Tail() as Usual
			if self:Length == 0
			   return nil
			endif
		return internalList[internalList:Count-1]
		#endregion

		#region static function
		public static Method Copy(aSource as __Array,aTarget as __Array,parameter params int[] ) as __Array
			throw NotImplementedException{"__Array.Copy is not implemented yet."}

		public static Method ArrayDelete(arrayToModify as __Array,position as dword)
			arrayToModify:RemoveAt(position)
			arrayToModify:Add(Usual{})
		return arrayToModify

		public static method ArrayCreate(dimensions params int[] ) as __Array
			local count := dimensions:Length as int
			if count <= 0
			   throw ArgumentException{"No dimensions provided."}
			endif
			local initializer := object[]{dimensions[1]} as object[]
			local arrayNew as __Array
			arrayNew := __Array{initializer}

			if count > 1
			   local i as int
			   for i:=0+__ARRAYBASE__  upto dimensions[1]-1+__ARRAYBASE__
					local newParams := int[]{count-1} as int[]
					Array.Copy(dimensions,1,newParams,0,count-1)
					arrayNew:internalList[i-__ARRAYBASE__ ] := ArrayCreate(newParams)
			   next
			endif
		return arrayNew

		public static method ArrayFill(arraytoFill as __Array,elementValue as Usual) as __Array
			return ArrayFill(arrayToFill, elementValue, 0,  arrayToFill:internalList:Count)

		public static method ArrayFill(arraytoFill as __Array,elementValue as Usual,start as int) as __Array
			return ArrayFill(arrayToFill, elementValue, start,  arrayToFill:internalList:Count- start)

		public static method ArrayFill(arraytoFill as __Array,elementValue as Usual,start as int, count as int) as __Array
			if start < 0
				throw ArgumentException{"Start index must be greater or equal zero."}
			endif
			if count < 0
				throw ArgumentException{"Count index must be greater or equal zero."}
			endif
			if arrayToFill:internalList:Count > 0
				local i as int
				for i:= start  upto start + count
					arraytoFill:internalList[i-__ARRAYBASE__] := elementValue
				next
			endif
		return arraytoFill
		#endregion
	END CLASS
END NAMESPACE

//
// Copyright (c) XSharp B.V.  All Rights Reserved.
// Licensed under the Apache License, Version 2.0.
// See License.txt in the project root for license information.
//
using System.Collections
using System.Collections.Generic
using System.Linq

BEGIN NAMESPACE Vulcan
	PUBLIC SEALED CLASS __Array IMPLEMENTS IEnumerable<Usual>
		private internalList as List<Usual>
		#region constructors
		CONSTRUCTOR()
			internalList := List<Usual>{}
		return

		CONSTRUCTOR(capacity as int)
			internalList := List<Usual>{capacity}
			internalList:AddRange(Enumerable.Repeat(nil,capacity))
		return

		CONSTRUCTOR( collection as IEnumerable<Usual>)
			internalList := List<Usual>{collection}
		return

		CONSTRUCTOR( elements as object[] )
		    self()
			if elements == null
				throw ArgumentNullException{"elemenst"}
			endif
			foreach element as object in elements
				internallist:Add(Usual{element})
			next
		return

		constructor( elements as Usual[] )
			internallist := List<Usual>{elements}
		return
		#endregion
		#region properties
		public Property IsEmpty as logic
			get
				return (internallist:Count == 0)
			end get
		end property

		public Property Length as dword
			get
				return (dword)internallist:Count
			end get
		end property
		#endregion
		#region helper functions
		public method Add(u as Usual) as void
			internallist:Add(u)
		return
		#endregion
		public method GetEnumerator() as IEnumerator<Usual>
		return internallist:GetEnumerator()

		public method IEnumerable.GetEnumerator() as IEnumerator
		return internallist:GetEnumerator()
		public static method ArrayNew( dimensions params int[] ) as __Array
			local newArray as __Array
			if dimensions:Length != 0
			   newArray := ArrayNewHelper(dimensions,1)
			else
			   newArray := __Array{}
			endif
		return newArray

		public static method ArrayNewHelper(dimensions as int[], currentDim as int) as __Array
			local capacity := dimensions[currentDim-1] as int // one based ?
			local newArray := __Array{capacity} as __Array

			if currentDim != dimensions:Length
			  local nextDim := currentDim+1 as int
			  local index   := 1 as int
			  do while index <= capacity
			     newArray:Add(Usual{ArrayNewHelper(dimensions,nextDIm)})
				 index+=1
			  enddo
			  return newArray
			endif
			local i as int
			for i:=1 upto capacity
				newArray:Add(Usual{})
			next
		return newArray

		public method Clone() as __Array
			throw NotImplementedException{"__Array.Clone is not implemented yet."}

		public method CloneShallow() as __Array
			throw NotImplementedException{"__Array.CloneShallow is not implemented yet."}

        ///
        /// <Summary>Access the array element using ZERO based array index</Summary>
        ///
		public method __GetElement(index params int[]) as Usual
			local indexLength := index:Length as int
			local currentArray := self as __Array
			local i as int

			for i:=0+__ARRAYBASE__  upto indexLength-2+__ARRAYBASE__
				local u := currentArray:internalList[ index[i]-__ARRAYBASE__] as Usual
				if u:IsNil
				   return nil
				endif
				if u:UsualType != UsualDataType.ARRAY
				   throw InvalidOperationException{"out of range error."}
				endif
				currentArray := (__Array) u
			next
			return currentArray:internalList[ index[i]-__ARRAYBASE__]

		public method Insert(index as dword,o as object) as void
			internallist:Insert((int)index-__ARRAYBASE__ ,Usual{o})
		return

		public method Insert(index as dword,u as Usual) as void
			internallist:Insert((int)index-__ARRAYBASE__ ,u)
		return

		public method Insert(position as dword) as __Array
			self:Insert(position,nil)
		return self

		public method RemoveAt(index as dword , count as int) as void
			internallist:RemoveRange((int)index-__ARRAYBASE__ ,count)
		return

		public method RemoveAt(index as dword) as void
			internallist:RemoveRange((int)index-__ARRAYBASE__,1 )
		return

		public method Resize(newSize as dword) as void
			local count := self:Length as dword
			if newSize == 0
			   internallist:Clear()
			else
				if newSize <= count
				   internallist:RemoveRange((int)newSize, (int)(count - newSize))
				else
				   count+=1
				   do while count <= newSize
					   local u := Usual{} as Usual
					   internallist:Add(u)
					   count++
			       enddo
				endif
			endif
		return

		public method ToString() as string
		return string.Format("{{[{0}]}}",internallist:Count)

		public method Sort(startIndex as int, count as int, comparer as IComparer<Usual>) as void
			internallist:Sort(startIndex-__ARRAYBASE__ ,count,comparer)
		return

		public method Size(size as dword) as __Array
			if size < 0
			   throw ArgumentException{"Size must be greate or equal zero."}
			endif
			if size > self:Length
			   local i as int
			   for i:=1-__ARRAYBASE__  upto size-__ARRAYBASE__
				   self:Add(Usual{})
			   next
			else
			   do while self:Length > size
			      self:RemoveAt(self:Length)
			   enddo
			endif
	    return self

		public Method Swap(position as dword, element as Usual)
			local original := internallist[(int) position - __ARRAYBASE__] as Usual
			internallist[(int) position - __ARRAYBASE__]:=element
		return original

		public Method __SetElement(u as Usual,index as int)
			internalList[index]:=u
		return u

		public Method __SetElement(u as Usual, index params int[] ) as Usual
			// indices are 0 based
			local length := index:Length as int
			local currentArray := self as __Array
			local i := 1 as int

			do while i <= length-__ARRAYBASE__
			   local uArray := internalList[index[i - __ARRAYBASE__ ]] as Usual
			   if !(uArray:UsualType == UsualDataType.ARRAY)
				  throw InvalidOperationException{"Out of range error."}
			   endif
			   currentArray := (__Array)uArray
			   i += 1
			enddo
			currentArray:internalList[index[i-1]] := u
		return u

		public Property self[index as dword] as Usual
			get
				VAR i := (int) index
				if i<__ARRAYBASE__ || i > System.Int32.MaxValue
					throw ArgumentOutOfRangeException{}
				endif
				return internalList[i - __ARRAYBASE__ ]
			end get
			set
				VAR i := (int) index
				if i<__ARRAYBASE__|| i > System.Int32.MaxValue
					throw ArgumentOutOfRangeException{}
				endif
				internalList[i-__ARRAYBASE__] := value
			end set
		end property

		public Property self[i as int] as Usual
			get
				if i<__ARRAYBASE__ || i > System.Int32.MaxValue
					throw ArgumentOutOfRangeException{}
				endif
				return internalList[i - __ARRAYBASE__ ]
			end get
			set
				if i<__ARRAYBASE__|| i > System.Int32.MaxValue
					throw ArgumentOutOfRangeException{}
				endif
				internalList[i-__ARRAYBASE__] := value
			end set
		end property

		public method Tail() as Usual
			if self:Length == 0
			   return nil
			endif
		return internalList[internalList:Count-1]
		#endregion

		#region static function
		public static Method Copy(aSource as __Array,aTarget as __Array,parameter params int[] ) as __Array
			throw NotImplementedException{"__Array.Copy is not implemented yet."}

		public static Method ArrayDelete(arrayToModify as __Array,position as dword)
			arrayToModify:RemoveAt(position)
			arrayToModify:Add(Usual{})
		return arrayToModify

		public static method ArrayCreate(dimensions params int[] ) as __Array
			local count := dimensions:Length as int
			if count <= 0
			   throw ArgumentException{"No dimensions provided."}
			endif
			local initializer := object[]{dimensions[1]} as object[]
			local arrayNew as __Array
			arrayNew := __Array{initializer}

			if count > 1
			   local i as int
			   for i:=0+__ARRAYBASE__  upto dimensions[1]-1+__ARRAYBASE__
					local newParams := int[]{count-1} as int[]
					Array.Copy(dimensions,1,newParams,0,count-1)
					arrayNew:internalList[i-__ARRAYBASE__ ] := ArrayCreate(newParams)
			   next
			endif
		return arrayNew

		public static method ArrayFill(arraytoFill as __Array,elementValue as Usual) as __Array
			return ArrayFill(arrayToFill, elementValue, 0,  arrayToFill:internalList:Count)

		public static method ArrayFill(arraytoFill as __Array,elementValue as Usual,start as int) as __Array
			return ArrayFill(arrayToFill, elementValue, start,  arrayToFill:internalList:Count- start)

		public static method ArrayFill(arraytoFill as __Array,elementValue as Usual,start as int, count as int) as __Array
			if start < 0
				throw ArgumentException{"Start index must be greater or equal zero."}
			endif
			if count < 0
				throw ArgumentException{"Count index must be greater or equal zero."}
			endif
			if arrayToFill:internalList:Count > 0
				local i as int
				for i:= start  upto start + count
					arraytoFill:internalList[i-__ARRAYBASE__] := elementValue
				next
			endif
		return arraytoFill
		#endregion
	END CLASS
END NAMESPACE


toDeBruijn is done

toDeBruijn is done

-- Modeling Opetopes
-- here is Eric's editor: http://sma.epfl.ch/~finster/opetope/opetope.html
--
-- Note: Kock et al. use a similar scheme, where
--          - dots    <-->   lines
--          - spheres <-->   dots
--          - lines disappear
--          -                spheres appear

-- Note: In Eric's new work (at IAS) there are no
--       dots any more, instead he uses 'external cards', so
--          - (external) cards   <-->  lines
--          - space between stacked cards <--> external cards
--          - lines disappear
--          -                (regular) cards appear

import "../src/LangPrelude.prg" (maybeM)
import "../tests/Nat.prg"

##bounds backchain 10

-- GLOBAL TODOs
----------------

-- Naming: Seems essential for identifying things Hor(Name), Ver(Tree)
--         Name can be Label, then Niches (= sequences of opetope names).
--         the latter arise from the composition rule.
--         Note: don't store names in Stacks, that kills alpha
--               conversion. Instead names should be pushed into nodes
--               'singleton style' from outside: (node :: Tree (Hor `g))

-- Morphisms: given an opetope and a pointer to one of its cards
--            extract the opetope of that face (do we need a label
--            space to reliably find it?). This must be a type
--            function, with an algorithm accompanying it to extract
--            the face proper.

-- Composition: grafting of trees to external cards, but only if the
--              morphisms (faces) match. lower-dim stuff is unaffected.

-- Swapping: given a proof of equality between two niches, provide an
--           operation to swap them, replacing old faces by new ones,
--           FGL-style (functional graph library), just note that
--           certain morphisms are gone, others appeared.

-- References: a disciplined way of saying "I am an identical node to that guy",
--             by corollary these always obtain the same names.
--             a topologist would say 'surgery' (http://en.wikipedia.org/wiki/Surgery_theory)
--             We get a new Tree flavour, Ref, at least one up, followed by
--             naturals to index a node in a subtree.
--             At this point we are doing algebraic topology, and dealing with
--             closed manifolds, so that we can do homology etc. on them.
--             In logic this corresponds to relations, satisfiability.

-- Quoting: So far we have only dealt with data, i.e. quoted (inert) syntax.
--          we need a way to convert this syntax to code (e.g. at some stage),
--          to obtain semantics. We can have the usual splicing game.
--          Lisp does this with sexprs and macros.
--          The code needs then be executed (run, decreasing stage), when
--          it becomes active, and we can observe the manifestation of its
--          semantics. The reduction system could go along the lines of the
--          (typed) LambdaGraph.

-- NbE: I fully believe we can use this technique to reduce opetopic terms
--      to normal form. ('many syntax', 'one semantics' adjunction:
--                       http://www.logicmatters.net/resources/pdfs/Galois.pdf)

-- TODO: these three must be LeftLists
--
kind Trees = NoTree | Pre (Tree d) Trees deriving syntax (ts) List(NoTree, Pre)

data ZoomCompley :: Tree e ~> Tree f ~> * where
  Nily :: ZoomCompley a a
  Consy :: Stack a b -> ZoomCompley b c -> ZoomCompley a c
 deriving List(cply)

data ZoomComplex :: Trees ~> * where
  Nilx :: ZoomComplex [()tr]ts
  Endx :: Stack a b -> ZoomComplex [a, b]ts
  Consx :: Stack a b -> ZoomComplex [b; c]ts -> ZoomComplex [a, b; c]ts
 deriving syntax (cplx) List(Nilx, Consx) Item(Endx)

data Dir :: *2 where
  Hor :: Dir
  Ver :: Dir

-- define the Tree kind, a rose tree
-- note: we may need a two-level kind, since we need to track disjointness
--       of subtrees
-- todo: later we may want to have a label kind parameter too

data Tree :: Dir ~> *1 where
  Unit :: Tree Ver
  Ni :: Tree Hor
  Fork :: Tree d ~> Tree Hor ~> Tree Hor
 deriving syntax (tr) List(Ni, Fork) Unit(Unit)

-- make it singleton

data Tree' :: Tree d ~> * where
  In :: Tree' ()tr
  Fork :: treelike head -> Tree' tail -> Tree' [head; tail]tr
  Done :: Tree' []tr
 deriving syntax (ar) List(Done, Fork) Unit(In) -- "arbre"
-- http://www.papoulipoesique.com/wp-content/uploads/2013/06/arbre.jpg

-- define a proposition for subtrees
-- to be checked: TakeHead must ensure that all the node is consumed

prop Subtree :: Tree d ~> Tree e ~> * where
  UnitSub :: Subtree ()tr tr
  BothNil :: Subtree []tr []tr
  TakeHead :: Subtree head head' -> Subtree tail tail' -> Subtree [head; tail]tr [head'; tail']tr

-- TODO: separate the notions of Niche / Frame / Cell
kind Volume = FramedHollow | FilledCell
kind Diagram = Closed Volume | OpenNiche
-- should be a parameter to Stack

-- now we can stack cards (these are zooms in Kock et al. parlance)

data Stack :: Tree d ~> Tree e ~> * where
  Corolla :: Corolla tr => Tree' tr -> Stack tr ()tr

  -- TODO: needed?
  --Expand :: (Subtree consumed tr, {nodeValence consumed} `Equal` {nodeValence tr}) => Stack consumed prod -> Stack tr prod

  -- add another target face to a web
  Target :: ({nodes tr} `Equal` {nodeValence out}) => Stack tr out -> Stack tr out

  -- the following three grab a node (and possibly its offsprings) and incorporate it into a single card
  NodeDone :: Stack []tr [()tr]tr
  Pick :: {- EntireNode => -} Stack head prodhead -> Stack tail prodtail -> Stack [head; tail]tr [prodhead; prodtail]tr
  Exclude :: {- EntireNode => -} Stack tail prod -> Stack [()tr; tail]tr prod
  -- TODO: maybe just specify a subtree (Tree') and that's it

  On :: (Subtree tr' tr, Pointers 1t at out) => Stack tr' out' -> Stack tr out -> Tree' at -> Stack tr {graft out' at out}

  -- building niches (pasting diagrams)
  -- TODO: these must produce a composite labelled Hor
  NicheDone :: Stack ()tr []tr
  Niche :: Stack tr out -> Stack tr [out]tr
  Also :: Pointers 1t at tr
       => Tree' at -> Stack tr' out' -> Stack tr out -> Stack {extgraft tr' at tr} [out'; out]tr

  -- put a frame around a niche
  Frame :: (Corolla out, {nodes tr}  `Equal` {nodeValence out}) => Stack tr out -> Stack tr out

 deriving syntax(z) Record(NicheDone, Also) Item(Target)

stop = ({}z)z

-- this is bogus, just make it compile again...
up :: Reference tr => Stack ()tr tr -> Stack ()tr [tr]tr
up inner = ({()ar=inner}z)z

-- it remains to define corollas

-- TODO: one could say {nodes tr} == 1
prop Corolla :: Tree d ~> * where
  None' :: Corolla []tr
  One' :: Corolla tail -> Corolla [()tr; tail]tr

--  o   --->  |
--  |         |

lolliCell :: Stack []tr ()tr
lolliCell = Corolla Done

--  |         |
--  o   --->  |
--  |         |

dolliCell :: Stack [()tr]tr ()tr
dolliCell = Corolla $ Fork In Done

--              |
--  [o]   --->  o
--   |          |

lolliFrame :: Stack []tr [()tr]tr
lolliFrame = Target NodeDone

--   |          |
--  [o]   --->  o
--   |          |

dolliFrame :: Stack [()tr]tr [()tr]tr
dolliFrame = Target (Exclude NodeDone)

--   |          |
--   |          o
-- [[o]]  --->  |
--   |          o
--   |          |

stacked :: Stack [()tr]tr [[()tr]tr]tr
stacked = (dolliFrame `On` dolliFrame) (In `Fork` Done)

--   |
--  [|]   --->  o
--   |          |

crossed :: Stack ()tr []tr
crossed = stop

-- we can now join things
--
dolliForever = [dolliFrame; dolliForever]cply
nopetope = [crossed, lolliFrame; dolliForever]cply

-- back to unit as fast as possible...
--
stopetope = [crossed, lolliFrame, dolliCell]cply
neverstopetope = [crossed, lolliFrame, dolliCell; neverstopetope]cply
stopetope' = [crossed, lolliFrame; (dolliCell)cplx]cplx
stopetope'' = [crossed, lolliFrame, dolliCell]cplx

--   |          o
-- [[|]]  --->  |
--   |          o
--   |          |

drossed :: Stack ()tr [[]tr]tr
drossed = up stop

-- ################################
-- ############  Niches ###########
-- ################################

--  |          +
--  |          |

-- this is a niche, but assume to be a frame
niche0 :: Stack ()tr []tr
niche0 = {}z

--  |           |
-- [|]          +
--  |           |

-- this is a niche, but assume to be a frame
niche1 :: Stack ()tr [[]tr]tr
niche1 = {()ar=stop; {}z}z

--  |         o   o
-- [|]  --->   \ /
-- [|]          +
--  |           |

-- this is a niche, but assume to be a frame
niche2 :: Stack ()tr [[]tr, []tr]tr
niche2 = {()ar=stop; niche1}z

--                |
--  |         o   o
-- [o]  --->   \ /
-- [|]          +
--  |           |

niche10 :: Stack [()tr]tr [[()tr]tr, []tr]tr
niche10 = {()ar=Exclude NodeDone; Niche stop}z

-- ################################
-- ############  Frames ###########
-- ################################

--   |              |
--  /|\         o   o
-- |[o]|  --->   \ /
-- |[|]|          o
--  \|/           |
--   |

cyclops :: Stack [()tr]tr [[()tr]tr, []tr]tr
cyclops = (niche10)z

-- Stacking, Valence, Affine subtree, Substitute at an affine position

-- counting Units in a tree

valence :: Tree d ~> Nat
{valence []tr} = 0t
{valence [head; tail]tr} = {plus {valence head} {valence tail}}
{valence ()tr} = 1t

-- counting siblings of a tree

nodeValence :: Tree d ~> Nat
{nodeValence []tr} = 0t
{nodeValence [head; tail]tr} = (1+{nodeValence tail})t

-- counting nodes in a tree

nodes :: Tree d ~> Nat
{nodes ()tr} = t
{nodes []tr} = 1t
{nodes [head; tail]tr} = {plus {nodes head} {nodes tail}}

-- nodeValenceAt: given a (multi)pointer, determine the node valences at those positions
--               WHERE     IN
nodeValenceAt :: Tree d ~> Tree e ~> Nat
{nodeValenceAt ()tr tree} = {nodeValence tree}
{nodeValenceAt []tr []tr} = 0t
{nodeValenceAt [head'; tail']tr [head; tail]tr} = {plus {nodeValenceAt head' head} {nodeValenceAt tail' tail}}

-- a pointer is a valence-1 subtree of a tree
-- it is used to mark a unit in a tree where substitution will occur
--
prop Pointers :: Nat ~> Tree d ~> Tree e ~> * where
  Finger :: Pointers 1t ()tr ()tr
  Finished :: Pointers 0t []tr []tr
  ThisWay :: Pointers 1t head' head -> Pointers n tail' tail -> Pointers (1+n)t [head'; tail']tr [head; tail]tr
  ElseWhere :: Pointers n tail' tail -> Pointers n [[]tr; tail']tr [head; tail]tr

-- http://en.wikipedia.org/wiki/Grafting
--
-- graft WHAT      WHERE     IN
graft :: Tree d ~> Tree e ~> Tree f ~> Tree f
{graft what ()tr ()tr} = what
{graft what []tr tr} = tr
{graft what [head'; tail']tr [head; tail]tr} = [{graft what head' head}; {graft what tail' tail}]tr

-- extgraft: extend and graft
--
extgraft :: Tree what ~> Tree wher ~> Tree tree ~> Tree tree'
{extgraft what ()tr ()tr} = what
{extgraft what []tr ()tr} = ()tr
{extgraft what [head; tail]tr ()tr} = {extgrafthor what [head; tail]tr}
{extgraft what []tr []tr} = []tr
{extgraft what []tr [head; tail]tr} = [head; tail]tr
{extgraft what [head'; tail']tr [head; tail]tr} = [{extgraft what head' head}; {extgraft what tail' tail}]tr

-- helper:
extgrafthor :: Tree what ~> Tree Hor ~> Tree Hor
{extgrafthor what []tr} = []tr
{extgrafthor what [head; tail]tr} = [{extgraft what head ()tr}; {extgrafthor what tail}]tr

{- NOTE: we have an Omega bug here:

prompt> :norm {graft []tr ()tr ()tr}
Normalizes to:
  []tr

prompt> :kind []tr
[]tr :: Tree Hor  = []tr

prompt> :kind {graft []tr ()tr ()tr}
{graft []tr ()tr ()tr} :: Tree Ver  = {graft []tr ()tr ()tr}

... BUT: Hor /= Ver :-(
-}

-- substitution: replace a pointed node (of valence n) in a tree with an
-- other tree of (valence n) -- TODO

-- HERE IS A NICE RESEARCH QUESTION:
-- is it possible to "proof search" a Zoom?
-- i.e.
{-

class ZoomLike (int :: Tree) (out :: Tree) where
  zoom :: (Nodes int ~ Valence out) => Zoom int out

-}

prop Reference :: Tree Hor ~> * where
  Stop :: Reference []tr
  Up :: Reference tr -> Reference [tr]tr
 deriving Nat(d) -- de Bruijn index

prop Teleport :: Tree Hor ~> * where
  Gate :: Teleport [()tr]tr
  Tele :: Teleport tr -> Teleport [tr]tr
 deriving Nat(sk) -- skips

{-

0
|   |
1   L  (lambda node)
|   |
2   1  (how many skips)
 \ /
  o
  |
  B  (binds here)
  |

Encodes \x.xx

-}

r2 = 2d
t1 = 1sk

lamX_XX = addBinder $ [r2, t1]ar

prop BindsUp :: Nat ~> Tree Hor ~> * where
  LastSkip :: BindsUp 1t [()tr]tr
  MoreSkip :: Teleport tr -> BindsUp n tr -> BindsUp (1+n)t [tr]tr
  -- prove Application node
  HeadBindsUp :: Nat' n -> BindsUp (1+n)t head -> BindsUp n [head; tail]tr
  TailBindsUp :: BindsUp n [head; tail]tr -> BindsUp n [nonempty, head; tail]tr

-- TODO: make sure that something teleports here
addBinder :: BindsUp 1t tr => Tree' tr -> Tree' [tr]tr
addBinder term = [term]ar

testB :: BindsUp 0t [[[[]tr]tr]tr,[()tr]tr]tr -> Tree' [[[[]tr]tr]tr,[()tr]tr]tr
testB ev = [r2, 0sk]ar
testB' = testB (TailBindsUp (HeadBindsUp 0v (LastSkip)))

testC :: BindsUp 0t [[[[[]tr]tr]tr,[[()tr]tr]tr]tr]tr -> Tree' [[[[[]tr]tr]tr,[[()tr]tr]tr]tr]tr
testC ev = lamX_XX
testC' = testC (HeadBindsUp 0v (TailBindsUp (HeadBindsUp 1v (MoreSkip 0sk LastSkip))))

--TODO: prop Lambda :: Tree Hor ~> * where

{-
The slogan is: binder nodes do not count as result nodes:
 - just consider the next node upstream
 - incoming (external) cards, when identified to a binder do not count as inputs to application
 - incoming (external) cards, when identified to an (iterated) application become pattern matching (sigma).

In the end all identifications have a semantics (hopefully!), when the counting rules are ensured.

-}

-- Now some fun stuff

data LC :: (k ~> *) ~> * where
  Var :: tf a -> LC tf
  App :: LC tf -> LC tf -> LC tf
  Lam :: tf a -> LC tf -> LC tf
  LetRec :: tf a -> LC tf -> LC tf -> LC tf
 deriving syntax (lc) Applicative(Var, App, Lam, LetRec)

alamX_XX = (\x->x x)lc

kind Dict key value = Dempty | Dextend (Dict key value) key value deriving LeftRecord(dict)

-- Contexts map keys to some value
--
data Context :: (key ~> *) ~> (value ~> *) ~> Dict key value ~> * where
  Empty :: Context key value {}dict
  Extend :: Context key value dict -> key k -> value v -> Context key value {dict; k = v}dict
 deriving LeftRecord(ctx)

-- DeBrujn levels as keys
--
dictSize :: Dict key value ~> Nat
{dictSize {}dict} = 0t
{dictSize {pre; k = v}dict} = (1+{dictSize pre})t

data DeBrujnContext :: (value ~> *) ~> Dict Nat value ~> * where
  DeBrujnEmpty :: DeBrujnContext value {}dict
  DeBrujnExtend :: DeBrujnContext value dict -> value v -> DeBrujnContext value {dict; {dictSize dict} = v}dict
 deriving LeftList(dtx)

getDeBruijnIndex :: Dict key value ~> value ~> Nat ~> Nat
{getDeBruijnIndex {pre; k = v}dict v acc} = acc
{getDeBruijnIndex {pre; k = v'}dict v acc} = {getDeBruijnIndex pre v (1+acc)t}

lookUpDeBruijn :: DeBrujnContext Label dict -> Label l -> Nat' acc -> Maybe (Nat' {getDeBruijnIndex dict l acc})
lookUpDeBruijn []dtx _ _ = Nothing
lookUpDeBruijn [pre; known]dtx lab acc = case sameLabel known lab of
                                         R _ -> lookUpDeBruijn pre lab (1+acc)t
                                         L Eq -> Just acc

monad maybeM

toDeBruijn :: DeBrujnContext Label dict -> LC Label -> Maybe (LC Nat')
toDeBruijn ctx (Var a) = do idx <- lookUpDeBruijn ctx a 0t
                            return $ Var idx
toDeBruijn ctx (Lam l a) = do a' <- toDeBruijn [ctx; l]dtx a
                              return $ Lam 0t a'
toDeBruijn ctx (App f a) = do f' <- toDeBruijn ctx f
                              a' <- toDeBruijn ctx a
                              return $ App f' a'