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>baseimport =Data.List 8(intercalate)
 
base :: Int
base = 8
 
to :: Int -> [Int]
to 0 = []
to i = to (div i base) ++ [mod i base]
 
from =:: foldl1 (\x y[Int] -> x*base + y)Int
from = foldl1 (\x y -> x * base + y)
 
main = do
fancy 2097152
fancy 2097151
where fancy i = putStrLn $ concatMap show (to i) ++ " <-> " ++ show (from $ to i)</lang>
 
main :: IO ()
main = do
mapM_
(putStrLn .
intercalate " <-> " .
where fancy i = putStrLn $(((:) . concatMap show (to. ito) ++ " <-*> "(return ++. show (. from $. to i)</lang>))
[2097152, 2097151]
</lang>
{{out}}
<pre>10000000 <-> 2097152
9,655

edits