Commit 5a94d528 authored by simonpj's avatar simonpj
Browse files

[project @ 2002-11-28 17:21:52 by simonpj]

Add new tests
parent b504edb3
-- Tests kind error messages
module ShouldFail where
data T k = T (k Int)
f :: [Maybe]
f x = x
g :: T Int
g x = x
h :: Int Int
h x = x
tcfail113.hs:7:
Kind error: `Maybe' is not applied to enough type arguments
In the type: [Maybe]
While checking the type signature for `f'
tcfail113.hs:10:
Kind error: Expecting kind `* -> *', but `Int' has kind `*'
When checking kinds in `T Int'
In the type: T Int
While checking the type signature for `g'
tcfail113.hs:13:
Kind error: `Int' is applied to too many type arguments
When checking kinds in `Int Int'
In the type: Int Int
While checking the type signature for `h'
{-# OPTIONS -fglasgow-exts #-}
module Main where
import Prelude hiding( succ, pred )
newtype Ch = Ch (forall a. (a -> a) -> a -> a)
apply :: Ch -> (a->a) -> a -> a
apply (Ch f) = f
instance Eq Ch where
a == b = isZero (a - b)
instance Show Ch where
show a = show (fromCh a)
instance Num Ch where
fromInteger n = toCh n
m + n = apply n succ m
m - n = apply n pred m
m * n = apply m (n +) zero
zero :: Ch
zero = Ch (\f z -> z)
succ :: Ch -> Ch
succ n = Ch (\f z -> f (apply n f z))
isZero :: Ch -> Bool
isZero n = apply n (const False) True
toCh :: Integer -> Ch
toCh 0 = zero
toCh n = succ (toCh (n-1))
fromCh :: Ch -> Int
fromCh n = apply n (+1) 0
pred :: Ch -> Ch
pred n = snd (apply n g (zero, zero))
where g (m,_) = (succ m, m)
main = print ((3+4)*12 - 10::Ch)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment