0

On running the following in GHCi:

:t 1:2

I get as output:

(Num [a], Num a) => [a]

While, running the following:

:t 'a':'b'

Gives me an error.

Personally, i fell that it should be a type error, but in case of Num that's not the case. Can anyone explain what's happening here?


What I mean is that, of course it shouldn't work, but checking the type in the Num case gives a result while in case of Char it gives an error.

Ashish
  • 1
  • 1
  • 1
    @leftaroundabout This is really non-obvious duplicate... – Eugene Sh. Aug 01 '17 at 18:26
  • @EugeneSh. you're right, this wasn't a very good match. I added a better one to the duplicates-list, we could certainly find more yet. The essential issue has been asked about plenty of times already, so I really rather wouldn't keep this question open. – leftaroundabout Aug 01 '17 at 18:49
  • Also compare `:t 1` to `:t 'a'`, and look at `:t 1 + 2`. Then try `:t (1::Int):2`. – molbdnilo Aug 01 '17 at 19:12
  • So @molbdnilo, basically, the reason that we get no error with `Num` case is because its a typeclass and we can have some type in the numeric hierarchy with the given type while `Char` is a specific type and here the system knows its wrong to say `'a':'b'` that's why it gave that error, right? – Ashish Aug 02 '17 at 01:47
  • Yeah, something like that, I think. (I'm not an expert). *If* you had a type `a` such that both `a` and `[a]` were instances of `Num`, the first would be valid. (Note that `1` and `2` have different types in `1:2`. Mysterious creature, that Haskell.) – molbdnilo Aug 03 '17 at 12:46

0 Answers0