@@ -11,14 +11,17 @@ data StrM : String -> Set where
11 StrNil : StrM ""
11 StrNil : StrM ""
12 StrCons : (x : Char) -> (xs : String) -> StrM (strCons x xs)
12 StrCons : (x : Char) -> (xs : String) -> StrM (strCons x xs)
14strHead' : (x : String) -> so (not (x == "")) -> Char
15strHead' : (x : String) -> so (not (x == "")) -> Char
15strHead' x p = prim__strHead x
16strHead' x p = prim__strHead x
17strTail' : (x : String) -> so (not (x == "")) -> String
19strTail' : (x : String) -> so (not (x == "")) -> String
18strTail' x p = prim__strTail x
20strTail' x p = prim__strTail x
20-- we need the 'believe_me' because the operations are primitives
22-- we need the 'believe_me' because the operations are primitives
22strM : (x : String) -> StrM x
25strM : (x : String) -> StrM x
23strM x with (choose (not (x == "")))
26strM x with (choose (not (x == "")))
24 strM x | (Left p) = believe_me $ StrCons (strHead' x p) (strTail' x p)
27 strM x | (Left p) = believe_me $ StrCons (strHead' x p) (strTail' x p)
@@ -71,11 +74,12 @@ words' s = case dropWhile isSpace s of
71words : String -> List String
74words : String -> List String
72words s = map pack $ words' $ unpack s
75words s = map pack $ words' $ unpack s
74foldr1 : (a -> a -> a) -> List a -> a
78foldr1 : (a -> a -> a) -> List a -> a
75foldr1 f [x] = x
79foldr1 f [x] = x
76foldr1 f (x::xs) = f x (foldr1 f xs)
80foldr1 f (x::xs) = f x (foldr1 f xs)
78−
82+%assert_total -- due to foldr1, but used safely
79unwords' : List (List Char) -> List Char
83unwords' : List (List Char) -> List Char
80unwords' [] = []
84unwords' [] = []
81unwords' ws = (foldr1 addSpace ws)
85unwords' ws = (foldr1 addSpace ws)
@@ -83,7 +87,6 @@ unwords' ws = (foldr1 addSpace ws)
83 addSpace : List Char -> List Char -> List Char
87 addSpace : List Char -> List Char -> List Char
84 addSpace w s = w ++ (' ' :: s)
88 addSpace w s = w ++ (' ' :: s)
87−unwords : List String -> String
90+unwords : List String -> String
88unwords = pack . unwords' . map unpack
91unwords = pack . unwords' . map unpack