ginger/types/types.go

39 lines
891 B
Go
Raw Normal View History

2014-10-06 22:20:25 +00:00
// This package describes ginger's base types and the interfaces covered by them
package types
import (
"fmt"
)
2014-10-06 22:20:25 +00:00
// Elem is a generic type which can be used as a wrapper type for all ginger
// types, both base types and data structures
type Elem interface {
2014-10-21 01:58:09 +00:00
// Returns whether one element is equal to another. Since all ginger values
// are immutable, this must be a deep-equals check.
Equal(Elem) bool
2014-10-06 22:20:25 +00:00
}
2014-10-15 00:13:10 +00:00
// Number can either be either an Int or a Float
type Number interface {
Elem
}
// Wraps a go type like int, string, or []byte. GoType is a struct whose only
// field is an interface{}, so using a pointer to is not necessary. Just pass
// around the value type.
type GoType struct {
V interface{}
}
func (g GoType) Equal(e Elem) bool {
if g2, ok := e.(GoType); ok {
return g.V == g2.V
}
return false
}
func (g GoType) String() string {
return fmt.Sprintf("%v", g.V)
2014-10-15 00:13:10 +00:00
}