[Haskell-cafe] Extending the idea of a general Num to other types?
Jonathan Cast
jcast at ou.edu
Wed Sep 5 09:16:00 EDT 2007
On Wed, 2007-09-05 at 19:50 +0200, Twan van Laarhoven wrote:
> Bulat Ziganshin wrote:
> > Hello Simon,
> >
> > Wednesday, September 5, 2007, 11:19:28 AM, you wrote:
> >
> >
> >> when you come across a case where GHC produces an
> >> unhelpful message, send it in, along with the program
> >> that produced it,
> >
> >
> > i have put such tickets about year ago :) basically, it was about
> > just changing wording: instead of "inferred" write:
> >
> > Expected type: ...
> > Actual type: ...
>
> This doesn't help enough. What is an 'expected' type? How is it not
> 'actual'? I want it to be immediatly clear which type is which.
>
> Say I write
> > "x" ++ 'y'
> Right now the error is
> Couldn't match expected type `[Char]' against inferred type `Char'
> In the second argument of `(++)', namely 'y'
>
> What always confuses me is which of these two types is the parameter I
> gave, and which is the one expected by the function? Changing 'infered'
> to 'actual' is an improvement, but it is not enough.
>
> I would suggest:
>
> (++) expects second argument to be of type '[Char]'
> but was given 'y' of type 'Char'
>
> Anothing thing that would be useful is *why* (++) expects a certian
> type, say I enter
> > "x" ++ [1::Int]
> Instead of the above, the following would be more useful:
>
> the function (++) has type: [a] -> [a] -> [a]
> the first argument suggests: a = Char
> the second argument suggests: a = Int
Maybe:
In the expression "x" ++ 'y':
(++) :: [a] -> [a] -> [a]
"x" :: String
'y' :: Char
(I expect the whole thing to have type String)
or
In the expression "x" ++ [1]:
(++) :: [a] -> [a] -> [a]
"x" :: String
[1] :: [Int]
(I expect the whole thing to have a type similar to [a])
jcc
More information about the Haskell-Cafe
mailing list