File: Half.curry

package info (click to toggle)
curry-tools 3.3.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 3,764 kB
  • sloc: perl: 282; ruby: 154; makefile: 119; sh: 106
file content (28 lines) | stat: -rw-r--r-- 496 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
-- Half of a natural number:

import Test.Prop


data Peano = O | S Peano
  deriving (Eq,Show)

toPeano :: Int -> Peano
toPeano n = if n==0 then O else S (toPeano (n-1))

fromPeano :: Peano -> Int
fromPeano O = 0
fromPeano (S p) = 1 + fromPeano p

add :: Peano -> Peano -> Peano
add O     p = p
add (S p) q = S (add p q)

half :: Peano -> Peano
half y | add x x === y
       = x
 where x free 

main :: Int
main = fromPeano (half (toPeano 100))

test_half = fromPeano (half (toPeano 100)) -=- 50