What should I specify as a type parameter in example #2 for it to work?
Also, it is not entirely clear for me why
() -> () and
() -> (()) are different types and are not compatible with each other.
I’ll answer here. Functions accept and return sequences of arguments. A binary function has a type
(T1, T2) -> .... A nullary function (accepting no arguments) has type
() -> ....
So far everything is standard.
When there is one input, then there is a twist. Assuming T1 is not syntactically a tuple type,
T1 -> ... and
(T1) -> ... are equivalent. This is because there are no one-tuples in Motoko. But if you have
(()) -> ... then this is a function that receives a unit (i.e. a single value of type
((T1, T2)) -> ... is a function type receiving a single argument of type
(T1, T2), i.e. a pair.
Same rules apply to the returned values side.