3 import qualified StdEnv
4 import StdEnv => qualified isEven, isOdd, class toInt(toInt), instance toInt Int
11 :: Two :== Succ (Succ Zero)
14 :: Three :== Succ (Succ (Succ Zero))
28 instance Even Zero True
29 instance Odd Zero False
30 instance Even (Succ a) b | Odd a b
31 instance Odd (Succ a) b | Even a b
38 (:+:) infixl 6 :: a b -> c
41 instance Add (Succ a) b (Succ c) | Add a b c
45 (:*:) infixl 7 :: a b -> c
47 instance Mult Zero b Zero
48 instance Mult (Succ a) b d | Mult a b c & Add b c d
52 (:^:) infixr 8 :: a b -> c
54 instance Pow a Zero One
55 instance Pow a (Succ b) d | Pow a b c & Mult a c d
60 { 'StdEnv'._createArray (size l+size r)
61 & [i]=l.[i], [size l+j]=r.[j]
62 \\ i<-[0..size l-1] & j <- [0..size r-1]
70 single :: a -> Vec (Succ Zero) a
73 length :: (Vec n a) -> n
76 nrepeat :: n a -> Vec n a | toInt n
77 nrepeat _ a = repeat a
79 repeat :: a -> Vec n a | toInt n
80 repeat a = let r = Vec (createArray (toInt (length r)) a) in r
82 append :: (Vec n a) (Vec m a) -> Vec x a | Add n m x
83 append (Vec a) (Vec b) = Vec (a +++ b)
89 instance Le Zero b True
90 instance Le (Succ a) Zero False
91 instance Le (Succ a) (Succ b) c | Le a b c
93 //Because toInt from StdEnv is strict in the first argument
94 class toInt a :: a -> Int
95 instance toInt Int where toInt i = i
96 instance toInt Zero where toInt _ = 0
97 instance toInt (Succ n) | toInt n where toInt a = inc (toInt (dec a))
99 (!!) infixl 9 :: (Vec n a) i -> a | Le (Succ i) n True & toInt i
100 (!!) (Vec a) i = a.[toInt i]
102 (=.) infixl 9 :: (Vec n a) (i, a) -> Vec n a | Le (Succ i) n True & toInt i
103 (=.) (Vec a) (i, x) = Vec {{e\\e<-:a} & [toInt i]=x}
105 :: A = A; :: B = B; :: C = C; :: D = D; :: E = E; :: F = F; :: G = G; :: H = H;
106 :: I = I; :: J = J; :: K = K; :: L = L; :: M = M; :: N = N; :: O = O; :: P = P;
107 :: Q = Q; :: R = R; :: S = S; :: T = T; :: U = U; :: V = V; :: W = W; :: X = X;
112 Start = nrepeat (Three :*: Three) 'a'
114 e1 :: Vec (Succ (Succ Zero)) Int
115 e1 = append (single 1) (single 32)