| 1 |
{-# OPTIONS --guardedness --sized-types #-} |
| 2 |
|
| 3 |
module Main where |
| 4 |
|
| 5 |
open import Data.Integer.Base using (ℤ; +_) |
| 6 |
import Data.Integer.Show as ℤ |
| 7 |
open import Data.List.Base as List using (List; _∷_; []) |
| 8 |
import Data.Nat.Base |
| 9 |
open import Data.Rational.Unnormalised.Base |
| 10 |
using (ℚᵘ; -_; _/_; floor; ceiling; truncate; round; fracPart) |
| 11 |
import Data.Rational.Unnormalised.Show as ℚᵘ |
| 12 |
open import Data.String.Base as String using (String) |
| 13 |
|
| 14 |
open import IO.Base |
| 15 |
open import IO.Finite |
| 16 |
open import Function.Base using (_$_) |
| 17 |
|
| 18 |
testList : List ℚᵘ |
| 19 |
testList = - (+ 35 / 10) ∷ - (+ 27 / 10) ∷ - (+ 15 / 10) ∷ - (+ 3 / 10) |
| 20 |
∷ + 3 / 10 ∷ + 15 / 10 ∷ + 27 / 10 ∷ + 35 / 10 ∷ [] |
| 21 |
|
| 22 |
showInts : List ℤ → String |
| 23 |
showInts is = String.concat |
| 24 |
$ "[" |
| 25 |
∷ String.intersperse ", " (List.map ℤ.show is) |
| 26 |
∷ "]" ∷ [] |
| 27 |
|
| 28 |
showRats : List ℚᵘ → String |
| 29 |
showRats ps = String.concat |
| 30 |
$ "[" |
| 31 |
∷ String.intersperse ", " (List.map ℚᵘ.show ps) |
| 32 |
∷ "]" ∷ [] |
| 33 |
|
| 34 |
main : Main |
| 35 |
main = run $ do |
| 36 |
putStrLn $ showInts (List.map floor testList) |
| 37 |
putStrLn $ showInts (List.map ceiling testList) |
| 38 |
putStrLn $ showInts (List.map truncate testList) |
| 39 |
putStrLn $ showInts (List.map round testList) |
| 40 |
putStrLn $ showRats (List.map fracPart testList) |