Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You don't use anything from <code>import Text.Printf</code>.</p> <p>Stylistically, you use more parentheses than necessary. Haskellers tend to find code more readable when it's cleaned of extraneous stuff like that. Instead of something like <code>h x = f (g x)</code>, write <code>h = f . g</code>.</p> <p>Nothing here really requires <code>Int</code>; <code>(Integral a) =&gt; a</code> ought to do.</p> <p><code>foldl (++) x xs</code> == <code>concat $ x : xs</code>: I trust the built-in <code>concat</code> to work better than your implementation.<br> Also, you should prefer <code>foldr</code> when the function is lazy in its second argument, as <code>(++)</code> is &ndash; because Haskell is lazy, this reduces stack space (and also works on infinite lists).<br> Also, <code>unwords</code> and <code>unlines</code> are shortcuts for <code>intercalate " "</code> and <code>concat . map (++ "\n")</code> respectively, i.e. "join with spaces" and "join with newlines (plus trailing newline)"; you can replace a couple things by those.</p> <p>Unless you use big numbers, <code>w = length $ takeWhile (&lt;= n) $ iterate (* b) 1</code> is probably faster. Or, in the case of a lazy programmer, let <code>w = length $ toBase b n</code>.</p> <p><code>concat ( (replicate ((w+1)* (n+2)) "-" )</code> == <code>replicate ((w+1) * (n+2)) '-'</code> &ndash; not sure how you missed this one, you got it right just a couple lines up.</p> <p>You do the same thing with <code>concat spaces</code>, too. However, wouldn't it be easier to actually use the <code>Text.Printf</code> import and write <code>printf "%*s " w digits</code>?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload