Is this legal Haskell code?
Yes, this is valid Haskell code. The point is that
the second expression is
; it is perfectly acceptable to shadow existing variables by defining a new variable with the same name. However, this does not affect the meaning of the external
. However, it was generally considered bad because of the potential for confusion and error; if you pass
to the GHC it issues a warning if you do.
It "crashes" at runtime because you defined
, which results in an infinite loop at runtime. This is due to laziness; basically,
evaluates both arguments before multiplying them. Evaluation
works great, of course, but evaluation
forces him to go through the same process over and over. The same thing that allows infinite lists (for example
ones = 1:ones
) makes this code an infinite loop.
source to share