[Haskell-beginners] A very counterintuitive behaviour of Haskell
Jonas Almström Duregård
jonas.duregard at chalmers.se
Thu Jan 27 16:35:27 CET 2011
> The problem comes from using the interpreter and not from haskell.
But a very similar 'problem' can be achieved in generic Haskell:
x = do
let f 7 = "yes"
let f x = "no"
putStrLn (f 7)
Arguably the compiler could issue a warning here because the second
'let' keyword might be intended to be spaces. I don't know how common
these mistakes are though.
I think the original poster suggests that the shadowing function
should only be used when the original function doesn't match. That is
more problematic if you ask me though.
/J
On 27 January 2011 16:09, jean verdier <verdier.jean at gmail.com> wrote:
> You have defined 2 functions that are called f and only the last
> definition is used (f x = "no").
> The definition you want should be written
> let f 7 = "ok"; f x = "no"
> so the function is defined once.
> The problem comes from using the interpreter and not from haskell.
>
>
> On Thu, 2011-01-27 at 15:55 +0100, Renzo Orsini wrote:
>> In studying Haskell, I produced the following output from GHC:
>>
>> xxx-3:~ xxx$ GHCi
>> GHCi, version 6.12.3: http://www.haskell.org/ghc/ :? for help
>> Loading package ghc-prim ... linking ... done.
>> Loading package integer-gmp ... linking ... done.
>> Loading package base ... linking ... done.
>> Loading package ffi-1.0 ... linking ... done.
>> Prelude> let f 7 = "ok"
>> Prelude> let f x = "no"
>> Prelude> f 3
>> "no"
>> Prelude> f 7
>> "no"
>>
>>
>> I suppose it is correct. However, for someone who is interested in the language, it seems very counterintuitive... Somebody would be so kind to explain to a neophyte this "feature" of the language?
>>
>> Thank you very much.
>>
>> Renzo
>> _______________________________________________
>> Beginners mailing list
>> Beginners at haskell.org
>> http://www.haskell.org/mailman/listinfo/beginners
>
>
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>
More information about the Beginners
mailing list