[Haskell-cafe] Type wildcards

Eyal Lotem eyal.lotem at gmail.com
Tue Dec 16 10:26:00 EST 2008


Martin Foster (aka. EvilTerran) suggested an interesting idea, and I decided
it was too nice to ignore/be forgotten inside Martin's head... So I'd like
to try and suggest it.

Type wildcards that allow partially specifying types, e.g:

f :: _ -> String
f x = show x

This will instruct the type-inferrer to "fill out" the wild-card part only
(e.g: Show a => a).

This feature can be used for a couple of benefits:

A. It allows hard-coding part of a type, rather than the all-or-nothing
situation we have now (I want to force a single parameter to be more
specific, but I'd still prefer to infer the whole type).

B. Without scoped type variables, there are currently situations you cannot
provide a type signature at all.  This may mean that you cannot resolve type
ambiguities in some cases, or make types more specific for some purpose.  A
type wild-card, in addition to scoped type variables, will allow to only
specify the part we want.

C. Its a nice way to kill the -Wall warnings about missing type
declarations, if you want to:

f :: _
f = "I am explicitly asking to infer this type, rather than specifying it"

Eyal
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20081216/7010e17a/attachment.htm


More information about the Haskell-Cafe mailing list