on master help sign in
Merge pull request #614 from Melvar/foldable-pack

Change Prelude.Strings.pack to work with Foldables

commite4d9c85fb4026b948bd5e5934ef3c365efe7256c authorEdwin Brady <edwin.brady@gmail.com> dateThu 14 Nov 2013, 12:04 (13 years ago) parentcda127476b48fc
2 files changed+4−4
lib/Prelude/Strings.idr+3−3 test/reg024/reg024.idr+1−1
lib/Prelude/Strings.idr+3−3
@@ -5,6 +5,7 @@ import Prelude.List
55import Prelude.Chars
66import Prelude.Cast
77import Prelude.Either
8+import Prelude.Foldable
89
910-- Some more complex string operations
1011
@@ -38,9 +39,8 @@ unpack s with (strM s)
3839 unpack "" | StrNil = []
3940 unpack (strCons x xs) | (StrCons x xs) = x :: unpack xs
4041
41−pack : List Char -> String
42−pack [] = ""
43−pack (x :: xs) = strCons x (pack xs)
42+pack : (Foldable t) => t Char -> String
43+pack = foldr strCons ""
4444
4545instance Cast String (List Char) where
4646 cast = unpack
test/reg024/reg024.idr+1−1
@@ -22,7 +22,7 @@ printf fmt = printFormat (fromList $ unpack fmt) where
2222 rec End acc = acc
2323 rec (FInt rest) acc = \i: Int => rec rest (acc ++ (show i))
2424 rec (FStr rest) acc = \s: String => rec rest (acc ++ s)
25− rec (FChar c rest) acc = rec rest (acc ++ (pack [c]))
25+ rec (FChar c rest) acc = rec rest (acc ++ (strCons c ""))
2626
2727test : String
2828test = printf "The %s is %d" "answer" 42