2014-10-06 22:20:25 +00:00
|
|
|
// This package describes ginger's base types and the interfaces covered by them
|
|
|
|
package types
|
|
|
|
|
2014-10-19 00:03:16 +00:00
|
|
|
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-19 00:03:16 +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 {
|
2014-10-19 00:03:16 +00:00
|
|
|
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
|
|
|
}
|