Re: [Haskell-cafe] About 'Overloaded functions are not your friend' line in GHC manual

At run-time, only the branch (Left/Right) is "picked" at run-time. For each branch, the "show" instance is determined at compile-time. The problem is that such instances are represented by dictionaries, and this adds extra cost (extra arguments) to function calls - but only in those cases where these dictionaries are not inlined (that is, removed) statically. But I am thinking that GHC has become very good at inlining. - J.W.

Only up to a point. Recursive uses — such as show, which delegates to other Show instances for record fields, etc. — are problematic. On Fri, Jan 11, 2019 at 1:04 PM Johannes Waldmann < johannes.waldmann@htwk-leipzig.de> wrote:
At run-time, only the branch (Left/Right) is "picked" at run-time. For each branch, the "show" instance is determined at compile-time.
The problem is that such instances are represented by dictionaries, and this adds extra cost (extra arguments) to function calls - but only in those cases where these dictionaries are not inlined (that is, removed) statically.
But I am thinking that GHC has become very good at inlining.
- J.W.
_______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post.
-- brandon s allbery kf8nh allbery.b@gmail.com

On 11.01.19 19:13, Brandon Allbery wrote:
Only up to a point. Recursive uses — such as show, which delegates to other Show instances for record fields, etc. — are problematic.
Please explain. Do you mean that size (S (S Z)) and size_N (S (S Z)) are not equivalent for these declarations? class Size t where size :: t -> Int data N = Z | S N instance Size N where size Z = 0 ; size (S n) = succ (size n) size_N Z = 0 ; size_N (S n) = succ (size n) I was trying to read core for this but I'm not sure what's the best way to call ghc. Which of the -ddump-* options is best suited (-ddump-simpl ?) and what do I look for in the output? Thanks - J.W.

Are you talking about instances such as Show a => Show (Maybe a)? If
the fields of a record are fixed types, it seems like GHC would be
able to inline the dictionaries.
On Fri, Jan 11, 2019 at 1:14 PM Brandon Allbery
Only up to a point. Recursive uses — such as show, which delegates to other Show instances for record fields, etc. — are problematic.
On Fri, Jan 11, 2019 at 1:04 PM Johannes Waldmann
wrote: At run-time, only the branch (Left/Right) is "picked" at run-time. For each branch, the "show" instance is determined at compile-time.
The problem is that such instances are represented by dictionaries, and this adds extra cost (extra arguments) to function calls - but only in those cases where these dictionaries are not inlined (that is, removed) statically.
But I am thinking that GHC has become very good at inlining.
- J.W.
_______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post.
-- brandon s allbery kf8nh allbery.b@gmail.com _______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post.
--
Dave Menendez
participants (3)
-
Brandon Allbery
-
David Menendez
-
Johannes Waldmann