1
$\begingroup$

Here's the code so far in "Type.h".

#pragma once

#include "Term.h"
#include <string>

class Type
{
public:
    Type() {
        typeName = "Anonymous";
    }
    Type(const std::string& typeName) 
    {
        this->typeName = typeName;
    }
    Type(const Type& source) 
    {
        typeName = source.typeName;
    }
    virtual ~Type();
    virtual std::string toString() const { return typeName;  }

protected:
    std::string typeName;
};

class DependentType : Type
{
public:
    DependentType(const Term& x, const Type& A, const std::string& typeName) : Type(typeName)
    {
        *term = x;
        *type = A;
    }

    virtual Type* operator () (const Term& x) = 0;

    std::string toString() const {
        return Type::toString() + ":" + type->toString() + "→" + "Universe";
    }

protected:
    Term* term;
    Type* type;
};

class PiType : public DependentType
{

};

There's this definition of dependent types on Wikipedia: https://en.wikipedia.org/wiki/Dependent_type#Formal_definition

But if a dependent type is defined to be loosely a family of types $B : A \to \mathcal{U}$ the universe, then I thought that only terms can go on the LHS of $:$ in $B(x) : \mathcal{U}$. If not, then I would need several typing judgements which seems bad on the code re-use side of things. Howe should I code it?

I'm guessing it's safe here to let Type subclass (derive from / inherit) Term as a base class. Is that right?

$\endgroup$
12
  • 1
    $\begingroup$ Does Type really do what $\mathcal U$ does? If you have const Type& A, can you then write const A& a? $\endgroup$
    – ice1000
    Commented Nov 14 at 2:30
  • 1
    $\begingroup$ If you intend to distinguish between types and C++ types, what are you trying to achieve? I thought you want to embed DT in C++, and I asked that to try to convince you that it is unlikely to happen, but it seems you are already aware of it. Are you trying to implement a type checker with support for dependent types? $\endgroup$
    – ice1000
    Commented Nov 14 at 2:44
  • 1
    $\begingroup$ Yes, ideally at least, in a dependently typed theory types are terms, aka types are first-class: which indeed is one of the cool features (or promises) of DTTs. I say ideally because that in full generality is not easily achievable (indeed at least Coq AFAIK does not have it full-fledged): but others will have to help you with more detailed and more technical explanations. $\endgroup$ Commented Nov 14 at 3:22
  • 1
    $\begingroup$ @IThinkHighlyOfEiligh maybe try to implement dependent function types (aka pi types)? $\endgroup$
    – ice1000
    Commented Nov 14 at 11:19
  • 1
    $\begingroup$ Found this really good book on DTT: carloangiuli.com/courses/b619-sp24/notes.pdf $\endgroup$ Commented Nov 15 at 4:04

1 Answer 1

0
$\begingroup$

Have been coding from the book. Here is a sample:

SimplyTypedLambdaCalculus::SimplyTypedLambdaCalculus(const Type* baseType)
{
    auto base_type = IsType(baseType);
    baseTypeIntro = InferenceRule({}, base_type);

    // Doing it like the below has two advantages:
    // 1. Each InferenceRule already makes copies that it owns (on the Heap), so this avoids doubling the heap allocs.
    // 2. Line-by-lines are great for debugging purposes.  To inspect each variable etc.

    auto A_type = IsType(A);
    auto B_type = IsType(B);
    auto AxB = Product(A, B);
    auto AxB_type = IsType(AxB);
    auto AtoB = Function(A, B);
    auto AtoB_type = IsType(AtoB);

    productTypeIntro = InferenceRule({ &A_type, &B_type }, AxB_type);
    functionTypeIntro = InferenceRule({ &A_type, &B_type }, AtoB_type);

    addInferenceRules({ &baseTypeIntro, &productTypeIntro, &functionTypeIntro });
}

The code is private, however.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.