Show.agda 785 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. {-# OPTIONS --no-termination-check #-}
  2. module Data.Show where
  3. import Prelude
  4. import Data.Nat
  5. import Data.Integer
  6. import Data.String
  7. import Data.List
  8. open Prelude
  9. open Data.Nat
  10. open Data.Integer using (Int; pos; neg)
  11. open Data.String
  12. open Data.List hiding (_++_)
  13. showNat : Nat -> String
  14. showNat zero = "0"
  15. showNat n = fromList $ reverse $ toList $ show n
  16. where
  17. digit : Nat -> String
  18. digit 0 = "0"
  19. digit 1 = "1"
  20. digit 2 = "2"
  21. digit 3 = "3"
  22. digit 4 = "4"
  23. digit 5 = "5"
  24. digit 6 = "6"
  25. digit 7 = "7"
  26. digit 8 = "8"
  27. digit 9 = "9"
  28. digit _ = "?"
  29. show : Nat -> String
  30. show zero = ""
  31. show n = digit (mod n 10) ++ show (div n 10)
  32. showInt : Int -> String
  33. showInt (pos n) = showNat n
  34. showInt (neg n) = "-" ++ showNat (suc n)