
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

Hi, On Tue, Dec 16, 2008 at 05:26:00PM +0200, Eyal Lotem wrote:
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).
What you are describing is (an instance of) the "some" operator. For example, see http://research.microsoft.com/en-us/um/people/daan/download/papers/hmf.pdf Section 5.1, "Partial annotations". And yes, I agree, they are useful :) Edsko

You can get pretty far with the same trick oleg mentions at [1]. If you use local type signature then you can do things like this:
{- ghci infers this type: *Main> :t f f :: (Ord a) => Int -> a -> t -> String -} f i j x | False = (undefined (i::Int) (isOrd j)) :: String f i j x = error "not filled in"
isOrd :: Ord a => a -> () isOrd = undefined
Cheers, Chris [1] http://okmij.org/ftp/Haskell/types.html#partial-sigs

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).
Also see http://hackage.haskell.org/trac/haskell-prime/wiki/PartialTypeAnnotations Cheers, Andres -- Andres Loeh, Universiteit Utrecht mailto:andres@cs.uu.nl mailto:mail@andres-loeh.de http://www.andres-loeh.de
participants (4)
-
Andres Loeh
-
ChrisK
-
Edsko de Vries
-
Eyal Lotem