Ethiopian multiplication: Difference between revisions

Content deleted Content added
Line 190: Line 190:


=={{header|Haskell}}==
=={{header|Haskell}}==
<lang haskell>ethiopicmult 1 pliand acc = acc + pliand
<lang haskell>ethiopicmult :: Integral a => a -> a -> a
ethiopicmult plier pliand acc
ethiopicmult x y = ethiopicmult' x y 0 where
| even plier = ethiopicmult (plier `div` 2) (pliand * 2) acc
ethiopicmult' 0 _ acc = acc
| otherwise = ethiopicmult (plier `div` 2) (pliand * 2) (acc + pliand)</lang>
ethiopicmult' plier pliand acc
| even plier = ethiopicmult' (plier `div` 2) (pliand * 2) acc
| otherwise = ethiopicmult' (plier `div` 2) (pliand * 2) (acc + pliand)</lang>


'''Usage example''' from the interpreter
'''Usage example''' from the interpreter
<pre>*Main> ethiopicmult 17 34 0
<pre>*Main> ethiopicmult 17 34
578</pre>
578</pre>