Partial type signatures
- Inferring type constructors
- Inferring constraints
- With ScopedTypeVariables
- Use during development
- No warning
In standard Haskell without the
PartialTypeSignatures GHC extension, type inference is a somewhat all-or-nothing affair. You can either omit the type signature for a function and let the compiler infer it,
or you can write a type signature yourself.
But what if we want to only specify part of the type and let the compiler infer the rest? You can do that by using a wildcard, represented by an underscore,It must be a single underscore with no other characters to be interpreted as a hole; a name with a leading underscore will be interpreted as a type variable. but this throws an error. What if you want to leave the holes in or get warnings instead of errors so that your code compiles?
PartialTypeSignatures extension, available in GHC 7.10 and later, can help.Official GHC documentation for
In this article, we show how to use the
PartialTypeSignatures extension and what kinds of things it can infer. We also discuss why you might want to take advantage of this feature during development so that you code can always compile despite possibly being not all written yet.