Difference between revisions of "Talk:Data.Semigroup"

From HaskellWiki
Jump to navigation Jump to search
(a counting error?)
 
(No difference)

Latest revision as of 08:04, 15 January 2020

The page says `stimes` applies the binary operation `x` times, while in fact, the binary operation is applied `x-1` times to `x` elements in total. In the example `3 * 3 * 3 * 3`, `*` is applied three times (not four), to four elements. Here is what the page currently (Jan, 2020) says:

stimes :: Integral b => b -> a -> a
Given a number x and a value of type a, apply <> to the value x times.
stimes 4 (Product 3) -- with the type "Product a" "<>" becomes "*"
-- returns: Product {getProduct = 81} 
-- This is because (3 <> 3 <> 3 <> 3) == (3 * 3 * 3 * 3) == 81
-- i.e. 3 multiplied by itself 4 times.