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

#14084: Strange behavior of GHC by writing the types in GHCi -------------------------------------+------------------------------------- Reporter: vanto | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: GHCi | Version: 8.0.2 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: -------------------------------------+------------------------------------- * A: you type {{{:set +t}}} then you write {{{1:2}}}, the answer is:\\ {{{ Prelude> :set +t }}} {{{ Prelude> 1:2 <interactive>:8:1: error: * Non type-variable argument in the constraint: Num [a] (Use FlexibleContexts to permit this) * When checking the inferred type it :: forall a. (Num [a], Num a) => [a] }}} \\ * B: you type {{{:t 1:2}}}, the answer is:\\ {{{ Prelude> :t 1:2 1:2 :: (Num [a], Num a) => [a] }}} \\ There is an obvious bug. Don't answer me that this behavior is correct, please! The two answers should be the same. Either answer A or answer B. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14084 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#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: | -------------------------------------+------------------------------------- Changes (by hsyl20): * status: new => closed * resolution: => invalid Comment: This behavior is correct. It has nothing to do with `:set +t`. B: `:t 1:2` just shows the inferred type for `1:2` A: {{{ Prelude> 1:2 }}} is equivalent to {{{ Prelude> let it = 1:2 }}} which fails to type-check the inferred type for `1:2` if you don't enable FlexibleContexts. Please [https://downloads.haskell.org/~ghc/8.2.1/docs/html/users_guide/ refer to the manual] and use [https://mail.haskell.org/mailman/listinfo/beginners this mailing-list] instead of the bug tracker when you don't understand GHC's behavior. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14084#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#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): @vanto, I think you'll get better explanations if you post these kind of questions on StackOverflow, or the beginners forum. If the people there tell you to report a bug, then come to Trac. (For comparison, I've been using GHC for over 10 years. I've never felt a need to raise a bug.) Briefly: this behaviour is correct. When you go {{{ Prelude> 1:2 }}} You are asking to evaluate the expression. (As well as give its type.) To evaluate the expression, GHC must figure out its type. Its type is indeed not Haskell2010-conformant: it needs `FlexibleContexts`. Contrariwise, when you go {{{ Prelude> :t ... }}} You are not asking to evaluate the expression. You are merely asking for its type. GHCi is being generous (I'd say) in telling you the type irrespective of whether that type is conformant with current settings/extensions. I see no bug. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14084#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#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 vanto): Reply. Thanks for the answers. Okay, you're right. Mea culpa, mea culpa, mea maxima culpa. Thank you for indicating where to ask questions. Truthfully I thought it was a bug.\\ However something is not right.\\ 1:2 is not a list. Where is the empty list [] ?\\ GHC should not be able to evaluate this expression which is poorly written. And yet it does. It's amazing.\\ It can with numbers but it can not with characters.\\ 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.\\ Intellectually this should be considered a bug.\\ {{{ Here are examples of lists: 1:2:3:[] [1,2,3] 1:2:undefined [1,2,..] 'a':'b':[] ['a','b'] }}} I'm going to open a new bug ticket soon. And that is not a request for information. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14084#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#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 hsyl20): @vanto
It can with numbers but it can not with characters.
It seems like you don't understand the type of numeric literals in Haskell. Please read https://www.haskell.org/onlinereport/basic.html#sect6.4.1 Then this will make sense: {{{#!hs
:t (:) (:) :: a -> [a] -> [a] :t 1 1 :: Num t => t :t (1:) (1:) :: Num a => [a] -> [a] :t (1:2) (1:2) :: (Num [a], Num a) => [a] }}}
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.
Probably because they aren't compilers for the same language. AFAIK ML compilers don't allow `1` to be used as a Float literal, we have to use `1.` instead. Different trade offs... -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14084#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#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

#14084: Strange behavior of GHC by writing the types in GHCi -------------------------------------+------------------------------------- Reporter: vanto | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: GHCi | Version: 8.0.2 Resolution: | 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: | -------------------------------------+------------------------------------- Changes (by vanto): * status: closed => new * resolution: invalid => Comment: Replying to [[span(style=color: #FF0000, AntC )]]:\\ I already know that. But your explanations, here and even above, lack precision and technicality. You should have said:\\ {{{ In Haskell, every expression must have a type, which is calculated prior to evaluating the expression by a process called "type inference". Graham Hutton, page 22, Chap 3, Types and classes. }}} I got the wrong word by writing evaluate instead of calculated. I do not speak the English language well. And sometimes I don't use the right words in my sentences.\\ But you also have to make an effort to understand.\\ Despite my lack of English language I make a lot of effort to read the best books about the Haskell language that are written in English. As you can see I also have other books about the Haskell language written by Hudak, Wadler, Bird.\\ I still get to understand what they are saying.\\ My sentences are sometimes poorly built and give the impression of dealing with a kid. But that is not true. I was already programming computers that you were not born yet.\\ Some of your writings have hurt me. * It is true I do not have the knowledge that you have of the Haskell language.\\ * I no longer have the age to write programs.\\ * Don't talk about my intellect. You don't know him.\\ * And you're the first one to tell me that I'm wasting your time.\\ One more thing:\\ I want this ticket closed by a member of the current Committee. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14084#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14084: Strange behavior of GHC by writing the types in GHCi -------------------------------------+------------------------------------- Reporter: vanto | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: GHCi | Version: 8.0.2 Resolution: | 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 goldfire): The role of the Committee is to decide on [https://github.com/ghc- proposals/ghc-proposals proposals]. That's it. We have no special authority here on Trac. GHC is a community-based compiler, and this is a community forum for posting and debating deficiencies in GHC. Bugs generally are instances where GHC's observable behavior differs from either the Haskell Report or its own manual. (I say "generally", because the manual is sometimes not as well-specified as it could be and thus the discrepancy may be a matter of interpretation. The Report is much tighter.) If some behavior in GHC conforms to the Report/manual, then it is not a bug. If that behavior seems wrong in some way (even if it matches the Report/manual), you may want to consider writing a proposal to change it. So: for the behavior originally reported above, do you see a way in which GHC's behavior differs from what should be expected from the Report and/or manual? We (@hsyl20, @AntC, and myself, at least) do not see such a discrepancy. This is why the ticket was closed. However, if you could point out the discrepancy -- not appealing to "logic" or "intuition", but appealing to the text of the Report and/or manual -- then perhaps we are the ones mistaken. On the other hand, if there is no discrepancy, please close the ticket. PS: I always think it's best if we assume good intentions on everyone's behalf and avoid discussions of individuals' characteristics (intellect, age, etc.). I've had a good many times where I've felt someone was wasting my time only to find, at the end of a long conversation, I've learned something new and interesting. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14084#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#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: | -------------------------------------+------------------------------------- Changes (by vanto): * status: new => closed * resolution: => invalid Comment: Reply to [[span(style=color: #FF0000, goldfire )]]:\\ Oh, I'm glad to read you, goldfire. OK. I understand. I have nothing in mind for the moment. I close this ticket.\\ One more thing: You're doing a good job, Ben and Ryan too. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14084#comment:8 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#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:6 vanto]:
Some of your writings have hurt me.
vanto, I apologise, I did not mean to hurt you. In both this ticket and #14076, you are saying something is wrong with Haskell/GHC. Several people patiently explained the behaviour is correct. They explained why it is correct. But you disagreed: "I'm going to open a new bug ticket soon ...". Please, before opening a ticket, think: maybe the behaviour is correct and there is something I don't understand. Then you can discuss that on another forum. People are very helpful on those forums: if they see some wrong GHC behaviour, they can help you open a bug ticket. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14084#comment:9 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC