-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDependentTypeIO.idr
52 lines (44 loc) · 1.7 KB
/
DependentTypeIO.idr
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
module DependentTypeIO
import Data.Vect
data VectOfUnkownLength : Type where
MkVectOfUnkownLength : (k : Nat) -> Vect k String -> VectOfUnkownLength
read_vect_desugarized : IO VectOfUnkownLength
read_vect_desugarized = do
cur_line <- getLine
if (cur_line == "") then
pure (MkVectOfUnkownLength 0 [])
else do
(MkVectOfUnkownLength len vect) <- read_vect_desugarized
pure (MkVectOfUnkownLength (S len) (cur_line :: vect))
read_and_zip_vectors_desugarized : IO()
read_and_zip_vectors_desugarized = do
putStrLn "Print first vector"
(MkVectOfUnkownLength first_len first_vect) <- read_vect_desugarized
putStrLn "Print second vector"
(MkVectOfUnkownLength second_len second_vect) <- read_vect_desugarized
case exactLength first_len second_vect of
Nothing => putStrLn "Cannot zip two vectors with different lengths"
Just new_second_vect => do
putStrLn "Zipped vector is"
let zipped = zip first_vect new_second_vect
printLn zipped
read_vect_of_unknown_length : IO (n : Nat ** Vect n String)
read_vect_of_unknown_length = do
cur_line <- getLine
if (cur_line == "") then
pure (_ ** [])
else do
(tail_length ** tail) <- read_vect_of_unknown_length
pure (S tail_length ** cur_line :: tail)
read_and_zip_vectors : IO()
read_and_zip_vectors = do
putStrLn "Print first vector"
(first_len ** first) <- read_vect_of_unknown_length
putStrLn "Print second vector"
(second_len ** second) <- read_vect_of_unknown_length
case exactLength first_len second of
Nothing => putStrLn "Cannot zip two vectors with different lengths"
Just new_second => do
putStrLn "Zipped vector is"
let zipped = zip first new_second
printLn zipped