-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathstring-format-issue.agda
More file actions
34 lines (26 loc) Β· 1.05 KB
/
string-format-issue.agda
File metadata and controls
34 lines (26 loc) Β· 1.05 KB
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
{- This file shows a natural attempt to do formatted printing, and where
that attempt goes wrong. See string-format.agda for a (working) solution
to this problem. -}
module string-format-issue where
open import char
open import eq
open import list
open import nat
open import nat-to-string
open import string
format-th : π char β Set
format-th ('%' :: 'n' :: f) = β β format-th f
format-th ('%' :: 's' :: f) = string β format-th f
format-th (c :: f) = format-th f
format-th [] = string
format-t : string β Set
format-t s = format-th (string-to-πchar s)
test-format-t : format-t "The %n% %s are %s." β‘ (β β string β string β string)
test-format-t = refl
format-h : π char β (f : π char) β format-th f
format-h s ('%' :: 'n' :: f) = Ξ» n β format-h (s ++ (string-to-πchar (β-to-string n))) f
format-h s ('%' :: 's' :: f) = Ξ» s' β format-h (s ++ (string-to-πchar s')) f
format-h s (c :: f) = {!!}
format-h s [] = πchar-to-string s
format : (f : string) β format-t f
format f = format-h [] (string-to-πchar f)