Partial type signatures

Since Version 1.1., Haskell for Mac supports partial type signatures. In Haskell, type signatures are almost always optional. They can be explicitly provided as a form of compiler-checked documentation, but they can also simply be inferred by the compiler. Sometimes, though, we would like a third option: we only want to explicitly provide part of a type signature. This may be because the signature is long, but most of it is obvious and we want to highlight the non-obvious portion. Or maybe, while prototyping, we don't want to fully commit yet. Or maybe, at a place where the compiler needs us to provide a concrete type, and that type is complicated, we only want to provide the needed portion.

The basic idea is that we can omit part of a type signature by writing an underscore character (_) instead of the type, such as in f :: [Int] -> _. Here f is a function that we require to expect a list of integers as its argument, but we do not constrain the result type.

The compiler will infer that part for us.

For a detailed explanation of partial type signatures, please have a look at the documentation in the user's guide of the Glasgow Haskell Compiler. You can ignore the compiler options needed to enable partial type signatures, though. In Haskell for Mac, this useful feature is active by default.

Have more questions? Submit a request


Please sign in to leave a comment.
Powered by Zendesk