feat: even and odd for Nat and Integral (#3021)

This commit is contained in:
scarf 2023-07-31 16:36:40 +09:00 committed by GitHub
parent 1fa638494d
commit c7abb148e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 77 additions and 0 deletions

View File

@ -175,6 +175,7 @@
* Adds `leftmost` and `rightmost` to `Control.Order`, a generalisation of `min` and `max`.
* Adds `even` and `odd` to `Data.Integral`.
* `Eq` and `Ord` implementations for `Fin n` now run in constant time.
* Adds `getTermCols` and `getTermLines` to the base library. They return the

View File

@ -0,0 +1,9 @@
module Data.Integral
export
even : Integral n => Eq n => n -> Bool
even n = n `mod` 2 == 0
export
odd : Integral n => Eq n => n -> Bool
odd = not . even

View File

@ -0,0 +1,52 @@
import Data.Integral
Cases : Type
Cases = List Bool
natEvenCases : Cases
natEvenCases = [
even 0,
even 2,
even 4,
even Z,
even (S (S Z))
]
natOddCases : Cases
natOddCases = [
odd 1,
odd 3,
odd 5,
odd (S Z),
odd (S (S (S Z)))
]
integralEvenCases : Cases
integralEvenCases = [
even (-4),
even (-2),
even 0,
even 2,
even 4
]
integralOddCases : Cases
integralOddCases = [
odd (-5),
odd (-3),
odd (-1),
odd 1,
odd 3,
odd 5
]
main : IO ()
main = do
printLn "Nat Even"
printLn natEvenCases
printLn "Nat Odd"
printLn natOddCases
printLn "Integral Even"
printLn integralEvenCases
printLn "Integral Odd"
printLn integralOddCases

View File

@ -0,0 +1,10 @@
1/1: Building Integral (Integral.idr)
Main> "Nat Even"
[True, True, True, True, True]
"Nat Odd"
[True, True, True, True, True]
"Integral Even"
[True, True, True, True, True]
"Integral Odd"
[True, True, True, True, True, True]
Main> Bye for now!

View File

@ -0,0 +1,2 @@
:exec main
:q

View File

@ -0,0 +1,3 @@
rm -rf build
$1 --no-color --console-width 0 --no-banner Integral.idr < input