E06100: implementation must be provided for generic function
What went wrong
A dynamic function made from an ABSTRACT generic function gives no body. An abstract generic function ('Transformer() of type T as abstract') is a legal signature to build from, but the dynamic function that parameterises it ('() is Transformer of String as function') must then supply the implementation, written in terms of the concrete type.
Worked examples
Compilable examples demonstrating this error and the correct fix:
- ek9 -q 649 (Why must generic functions provide an implementation?)
Rationale
An abstract generic function describes a shape - its parameters and return in terms of T - and nothing more. A dynamic function that is 'Transformer of String' fixes T, and is the only place left to say what the function DOES; without a body there is nothing to call.
[USAGE - PARAMETERIZE AT USE SITE] The [EXAMPLE] section below shows the dynamic function with no body, and the same dynamic function giving its body ('result: ...' from its 'input').
How to fix it
- Give the dynamic function a body that sets the returning variable
- Or build it from a generic function that already has a body
Common causes
- Wanting to defer implementation (generics don't work this way)
- Confusing generic with abstract (different concepts)
- Coming from languages where generics can be abstract
See also
Examples
Every example is compiled by the EK9 compiler: the first fails exactly as captioned, the others fix it.
Fails with E06100: implementation must be provided for generic function
#!ek9 defines module error.e06100.bad defines function Transformer() of type T as abstract -> input as T <- result as T? defines program Transform() stdout <- Stdout() //A dynamic function of an abstract generic function must give the body transformer <- () is Transformer of String as function stdout.println(transformer("text"))
Fixed: Give the dynamic function its body; it takes the parameters and return of Transformer of String
#!ek9 defines module error.e06100.good defines function Transformer() of type T as abstract -> input as T <- result as T? defines program Transform() stdout <- Stdout() transformer <- () is Transformer of String as function result: `${input} processed` stdout.println(transformer("text"))