Opaque Value - anssihalmeaho/funl GitHub Wiki

Opaque value

Opaque value is such value that FunL code is able to see values of such type but implementation of opaque value is visible only in code implemented with Go.

Opaque value can be received from external procedures and given to those as argument but visibility to opaque value content is restricted in FunL code to several issues:

  • specific opaque type "type name" (for example type -operator)
  • opaque value as string representation (for example str -operator or sprintf)
  • equality check of opaque values (used by eq -operator)

To implement opaque type in Go code it needs to give implementation for following interface:

//OpaqueAPI is interface for opaque type
type OpaqueAPI interface {
	TypeName() string
	Str() string
	Equals(with OpaqueAPI) bool
}

Opaque value would be constructed for example following way:

funl.Value{Kind: funl.OpaqueValue, Data: &myOpaqueType{}}