There are three ways you can compile your code.
Method 1
You can disable the monomorphism restriction.
{-# LANGUAGE NoMonomorphismRestriction #-}
The monomorphism restriction comes into play because func3
is not defined using function syntax. Which leads to method 2:
Method 2
If you had done this instead:
func3 x = func . func $ x
Everything would have been fine. The monomorphism restriction is a rule that protects you from "accidentally" defining a polymorphic value. It is known to be a little too restrictive in some common cases, and it is a deviation from standard Hindley-Milner type inference.
Method 3
Of course, the final thing you can do, is to give your function an explicit type signature.
func3 :: Show a => a -> a
func3 = func . func
The monomorphism restriction means that any value which is declared without function syntax (i.e., the left hand side of the =
has no parameters) will not get a polymorphic type derived automatically.