@@ -45,7 +45,8 @@ foldl1 f (x::xs) = foldl f x xs
47strHead : String -> Char
47strHead : String -> Char
48+strHead "" = idris_crash "Prelude.Strings: attempt to take the head of an empty string"
48−strHead = prim__strHead
49+strHead x = prim__strHead x
50||| Returns the characters specified after the head of the string.
51||| Returns the characters specified after the head of the string.
@@ -59,7 +60,8 @@ strHead = prim__strHead
61strTail : String -> String
62strTail : String -> String
63+strTail "" = idris_crash "Prelude.Strings: attempt to take the tail of an empty string"
62−strTail = prim__strTail
64+strTail xs = prim__strTail xs
64||| Adds a character to the front of the specified string.
66||| Adds a character to the front of the specified string.
@@ -72,6 +74,18 @@ strTail = prim__strTail
72strCons : Char -> String -> String
74strCons : Char -> String -> String
73strCons = prim__strCons
75strCons = prim__strCons
77+||| Returns the length of the string.
85+length : String -> Nat
86+length = fromInteger . prim__zextInt_BigInt . prim_lenString
75||| Returns the nth character (starting from 0) of the specified string.
89||| Returns the nth character (starting from 0) of the specified string.
77||| Precondition: '0 < i < length s' for 'strIndex s i'.
91||| Precondition: '0 < i < length s' for 'strIndex s i'.
@@ -81,7 +95,9 @@ strCons = prim__strCons
83strIndex : String -> Int -> Char
97strIndex : String -> Int -> Char
98+strIndex x i = if (i < 0 || i >= cast (length x))
99+ then idris_crash "Prelude.Strings: String index out of bounds"
84−strIndex = prim__strIndex
100+ else prim__strIndex x i
86||| Reverses the elements within a String.
102||| Reverses the elements within a String.
@@ -297,17 +313,6 @@ unlines' (l::ls) = l ++ '\n' :: unlines' ls
297unlines : List String -> String
313unlines : List String -> String
298unlines = pack . unlines' . map unpack
314unlines = pack . unlines' . map unpack
300−||| Returns the length of the string.
308−length : String -> Nat
309−length = fromInteger . prim__zextInt_BigInt . prim_lenString
311||| Returns a substring of a given string
316||| Returns a substring of a given string
313||| @ index The (zero based) index of the string to extract. If this is
318||| @ index The (zero based) index of the string to extract. If this is