Variable-length quantity: Difference between revisions
→{{header|Haskell}}: Added type signatures, slight tidying
(→{{header|Haskell}}: Added type signatures, slight tidying) |
|||
Line 670:
Homemade Version:
<lang Haskell>
base :: Int
base = 8
to :: Int -> [Int]
to 0 = []
to i = to (div i base) ++ [mod i base]
from
from = foldl1 (\x y -> x * base + y)
main = do▼
where fancy i = putStrLn $ concatMap show (to i) ++ " <-> " ++ show (from $ to i)</lang>▼
main :: IO ()
mapM_
(putStrLn .
intercalate " <-> " .
▲
[2097152, 2097151]
</lang>
{{out}}
<pre>10000000 <-> 2097152
|