nOfThem,
lengthExceeds, lengthIs, lengthAtLeast, listLengthCmp, atLength,
isSingleton, only,
- notNull,
+ notNull, snocView,
- snocView,
isIn, isn'tIn,
-- for-loop
unzipWith,
global,
+
+ -- module names
+ looksLikeModuleName,
) where
#include "../includes/config.h"
import List ( zipWith4 )
#endif
+import Char ( isUpper, isAlphaNum )
+
infixr 9 `thenCmp`
\end{code}
notNull [] = False
notNull _ = True
+snocView :: [a] -> Maybe ([a],a)
+ -- Split off the last element
+snocView [] = Nothing
+snocView xs = go [] xs
+ where
+ -- Invariant: second arg is non-empty
+ go acc [x] = Just (reverse acc, x)
+ go acc (x:xs) = go (x:acc) xs
+
only :: [a] -> a
#ifdef DEBUG
only [a] = a
#endif
\end{code}
-\begin{code}
-snocView :: [a] -> ([a], a) -- Split off the last element
-snocView xs = go xs []
- where
- go [x] acc = (reverse acc, x)
- go (x:xs) acc = go xs (x:acc)
-\end{code}
-
Debugging/specialising versions of \tr{elem} and \tr{notElem}
\begin{code}
global :: a -> IORef a
global a = unsafePerformIO (newIORef a)
\end{code}
+
+Module names:
+
+\begin{code}
+looksLikeModuleName [] = False
+looksLikeModuleName (c:cs) = isUpper c && all isAlphaNumEx cs
+
+isAlphaNumEx c = isAlphaNum c || c == '_' || c == '.'
+\end{code}