Skip to content

Commit

Permalink
Added a few methods and a couple of interfaces for Monuples and Pairs
Browse files Browse the repository at this point in the history
  • Loading branch information
chewxy committed Jan 4, 2018
1 parent 44a2cf0 commit 0327ec5
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
12 changes: 12 additions & 0 deletions types/commonutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,15 @@ func (t Monuple) Normalize(k, v hm.TypeVarSet) (Monuple, error) {
t.T = t2
return t, nil
}

// Pairer is any type that can be represented by a Pair
type Pairer interface {
hm.Type
AsPair() *Pair
}

// Monupler is any type that can be represented by a Monuple
type Monupler interface {
hm.Type
AsMonuple() Monuple
}
6 changes: 6 additions & 0 deletions types/monuples.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ func (t Slice) Eq(other hm.Type) bool {
return false
}

func (t Slice) Monuple() Monuple { return Monuple(t) }

// Linear is a linear type (i.e types that can only appear once)
type Linear Monuple

Expand All @@ -56,6 +58,8 @@ func (t Linear) Eq(other hm.Type) bool {
return false
}

func (t Linear) Monuple() Monuple { return Monuple(t) }

// Ref is a reference type (think pointers)
type Ref Monuple

Expand All @@ -80,3 +84,5 @@ func (t Ref) Eq(other hm.Type) bool {
}
return false
}

func (t Ref) Monuple() Monuple { return Monuple(t) }
12 changes: 12 additions & 0 deletions types/pairs.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ func (t *Choice) Eq(other hm.Type) bool {
return false
}

func (t *Choice) Clone() interface{} { return (*Choice)((*Pair)(t).Clone()) }

func (t *Choice) Pair() *Pair { return (*Pair)(t) }

// Super is the inverse of Choice. It allows for supertyping functions.
//
// Supertyping is typically implemented as a adding an entry to the vtable/mangled table.
Expand Down Expand Up @@ -78,6 +82,10 @@ func (t *Super) Eq(other hm.Type) bool {
return false
}

func (t *Super) Clone() interface{} { return (*Super)((*Pair)(t).Clone()) }

func (t *Super) Pair() *Pair { return (*Pair)(t) }

// Application is the pre-unified type for a function application.
// In a simple HM system this would not be needed as the type of an
// application expression would be found during the unification phase of
Expand Down Expand Up @@ -105,3 +113,7 @@ func (t *Application) Eq(other hm.Type) bool {
}
return false
}

func (t *Application) Clone() interface{} { return (*Application)((*Pair)(t).Clone()) }

func (t *Application) Pair() *Pair { return (*Pair)(t) }

0 comments on commit 0327ec5

Please sign in to comment.