title: Declare a function type with an arbitrary return type in golang
body: <p>I'm new to go and have come across the following issue that I haven't been able to find covered in the tutorial or google searches, though I'm sure it must be a basic aspect of the language I have missed. I have code like the following:</p>
  
  <pre><code>type Task func()
  
  var f Task = func() { fmt.Println("foo") }
  
  type TaskWithValue func() interface{}
  
  var g TaskWithValue = func() { return "foo" }
  
  var h TaskWithValue = func() { return 123 }
  </code></pre>
  
  <p>In <code>f</code> above, there is no compiler error, but for <code>g</code> and <code>h</code> there are errors like the following:</p>
  
  <pre><code>Cannot use func() { return "foo" } (type func ()) as type TaskWithValue in assignment
  </code></pre>
  
  <p>Essentially, I'm trying to define a <code>Task</code> type that can have an arbitrary return type. In other languages, I would simply give <code>Task</code> a type parameter, like <code>Task&lt;Integer&gt;</code> or <code>Task&lt;String&gt;</code>, but since go does not have generics/templates, I understood the workaround is to use return type <code>interface{}</code> and then cast the results. What am I missing to get this example working?</p>