#9250 closed bug (invalid)

let makes function too much specific

Reported by: KommuSoft Owned by:
Priority: low Milestone:
Component: Compiler Version: 7.6.3
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: x86_64 (amd64)
Type of failure: Incorrect result at runtime Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):

Description (last modified by KommuSoft)

Say you define a myadd function:

let myadd x y = x + y

Then the type is Num a => a -> a -> a. If on the other hand, you define the method using currying:

let myadd2 \x -> \y -> x + y

The type is more specific: Integer -> Integer -> Integer. Strangely enough :t \x -> \y -> x + y returns the more general form.

URL: http://stackoverflow.com/questions/24481024/why-does-currying-anonymous-functions-change-haskells-type-inference-from-num-t

Change History (2)

comment:1 Changed 16 months ago by KommuSoft

  • Description modified (diff)

comment:2 Changed 16 months ago by simonpj

  • Resolution set to invalid
  • Status changed from new to closed

There are good answers on StackOverflow. I believe, though you do not say so, that you are describing GHCi. let does generalisation, subject to the monomorphism restriction (like all top level bindings); :type ignores the monomorphism restriction (it isn't a top level binding).

Do re-open if you think there is a bug here.

Note: See TracTickets for help on using tickets.