[GHC] #14084: Strange behavior of GHC by writing the types in GHCi

GHC ghc-devs at haskell.org
Fri Aug 4 01:17:48 UTC 2017


#14084: Strange behavior of GHC by writing the types in GHCi
-------------------------------------+-------------------------------------
        Reporter:  vanto             |                Owner:  (none)
            Type:  bug               |               Status:  closed
        Priority:  normal            |            Milestone:
       Component:  GHCi              |              Version:  8.0.2
      Resolution:  invalid           |             Keywords:
Operating System:  Unknown/Multiple  |         Architecture:
 Type of failure:  Incorrect result  |  Unknown/Multiple
  at runtime                         |            Test Case:
      Blocked By:                    |             Blocking:
 Related Tickets:                    |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------

Comment (by AntC):

 Replying to [comment:3 vanto]:
 > However something is not right.\\

 Chiefly, that you do not understand Haskell's typeclass system and
 overloading. GHCi is great for 'quick qnd dirty' experimenting; but I note
 you haven't actually written a program yet. So to head you off from
 alleging more bugs that are not bugs ...

 > 1:2 is not a list. Where is the empty list [] ?\\

 If you try to put (say) `x = 1:2` in a program, it won't compile. So you
 can not make any claims about what `1:2` is or is not. What GHCi's `:t
 1:2` is telling you is:
  * if you supply some specific type (call it `a0`);
  * and you have `instance Num a0` and `instance Num [a0]`;
  * then you'll have a list type `[a0]`.

 Note there is no `instance Num a => Num [a]` in the Prelude, but for all
 GHCi knows, perhaps you're about to load a program that supplies one.
 Perhaps the reason you're asking for `:t 1:2` is precisely because you're
 doing that, and you want to check first. It would be really annoying if
 GHCi didn't play ball.

 > GHC should not be able to evaluate this expression which is poorly
 > written. And yet it does. It's amazing.\\

 No it doesn't evaluate nothing. `:t` is not evaluating (as I said); it's
 telling you what you need to supply, in order to evaluate. You've tried
 putting `1:2` and you got an error message; no evaluating. Even if you
 `:set -FlexibleContexts`, you'll still get a (different) error message.
 It'll (probably) talk about `No instance for Show [a0] ...`. That's not a
 bug; and it's not evaluating.

 As another example of that, put `x = 1:2:[]` in a program and compile it.
 Then ask `:t x`. Please do not report that as a bug. You'll be learning
 about default typing.

 > It can with numbers but it can not with characters.\\

 Who says characters are not `Num`eric? Try this at the prompt: `:t 1 +
 'c'`. This is also not a bug.

 > The ML and Miranda compilers, for example, do not manage to
 > evaluate this kind of poorly written list, as well as with numbers or
 characters.\\

 Haskell does not evaluate this kind of poorly written list. (Unless you
 supply extra instances over what's in the Prelude.) Same same.

 > Intellectually this should be considered a bug.\\

 That's a comment on your intellect. You could go and find a copy of Hugs.
 That represents Haskell of ~10 years ago. You'll see exactly the same
 behaviour. You could go and read Wadler&Blott's 1988 paper that formalised
 the typeclass system (and compared to ML and Miranda). You'll see exactly
 the same, and why Haskell is a huge improvement.

 > I'm going to open a new bug ticket soon. And that is not a request for
 information.

 Then you're going to be wasting a lot of people's time. Putting `1:2` at
 the GHCi prompt is a way to start learning, OK. You've spent 2~3 days at
 it. Most people get over it in an hour or so. I suggest you get on with
 some proper programming.

-- 
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/14084#comment:5>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list