4plus : Nat -> Nat -> Nat
6plus (S x) y = S (plus x y)
9data Vect : Nat -> Type -> Type where
11 (::) : a -> Vect k a -> Vect (S k) a
15append : Vect n a -> Vect m a -> Vect (n + m) a
17append (x :: xs) ys = x :: append xs ys
20zipWith : (a -> b -> c) -> Vect n a -> Vect n b -> Vect n c
22zipWith f (x :: xs) (y :: ys) = f x y :: zipWith f xs ys
24create_empties : Vect m (Vect 0 elem)
25create_empties {m = Z} = []
26create_empties {m = (S k)} = [] :: create_empties
28transpose_helper : (row : Vect m elem) -> (rest_trans : Vect m (Vect k elem)) ->
29 Vect m (Vect (S k) elem)
30transpose_helper [] [] = []
31transpose_helper (rowval :: xs) (restrow :: ys) = (rowval :: restrow) :: transpose_helper xs ys
33transpose_vec : Vect n (Vect m elem) -> Vect m (Vect n elem)
34transpose_vec [] = create_empties
35transpose_vec (row :: rest) = let rest_trans = transpose_vec rest in
36 transpose_helper row rest_trans
45------- A main program to read dimensions, generate and tranpose a vector
47instance Functor (Vect m) where
49 map m (x :: xs) = m x :: map m xs
51instance Show a => Show (Vect m a) where
52 show x = show (toList x)
54 toList : Vect m a -> List a
56 toList (y :: xs) = y :: toList xs
58countTo : (m : Nat) -> Vect m Int
60countTo (S k) = 0 :: map (+1) (countTo k)
62mkVect : (n, m : Nat) -> Vect n (Vect m Int)
64mkVect (S k) m = countTo m :: map (map (+ cast m)) (mkVect k m)
67main = do putStr "Rows: "
72 putStrLn "Transposed:"
73 printLn (transpose_vec (mkVect r c))
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list