Permalink
Browse files

Compiles against new saliva codebase.

  • Loading branch information...
1 parent 7776077 commit 7c9a8551ccb8668bd81dd6fa50b759570790cb3c Sebastiaan Visser committed Feb 25, 2010
View
@@ -1,3 +1,2 @@
cabal configure &&
-./prepare.sh
cabal build
View
@@ -9,26 +9,27 @@ License-file: LICENSE
Author: Sebastiaan Visser
Maintainer: sfvisser@cs.uu.nl
Build-Type: Simple
-Build-Depends: base ==3.0.*,
- bytestring == 0.9.*,
- salvia == 0.3.*,
- salvia-extras == 0.3.*,
- orchid-doc == 0.0.*,
- xml ==1.3.*,
- extensible-exceptions ==0.1.*,
- containers ==0.2.*,
- parsec ==3.0.*,
- fclabels ==0.2.*,
- filestore ==0.3.*,
- monads-fd ==0.0.*,
- transformers ==0.1.*,
- encoding ==0.5.*,
- time ==1.1.*,
- stm ==2.1.*,
- process ==1.0.*,
- unix ==2.3.*,
- nano-md5 ==0.1.*,
- hscolour ==1.11.*
+Build-Depends: base,
+ bytestring,
+ salvia-protocol,
+ salvia,
+ salvia-extras,
+ orchid-doc,
+ xml,
+ extensible-exceptions,
+ containers,
+ parsec,
+ fclabels,
+ filestore,
+ monads-fd,
+ transformers,
+ encoding,
+ time,
+ stm,
+ process,
+ unix,
+ nano-md5,
+ hscolour
GHC-Options: -fglasgow-exts -threaded
Extensions: CPP
HS-Source-Dirs: src
View
@@ -3,16 +3,12 @@
module Misc.Commons where
import Control.Applicative
-import Control.Concurrent
import Control.Concurrent.STM
-import Control.Monad (liftM, liftM2, ap, mzero, mplus)
-import Control.Monad.Identity
+import Control.Monad (liftM, liftM2)
import Data.Char
import Data.Time.Clock
import Data.Time.LocalTime
import Text.ParserCombinators.Parsec hiding (many, optional, (<|>))
-import Text.ParserCombinators.Parsec.Pos (updatePosChar)
-import Text.Printf (printf)
import Data.List (partition, tails, inits, isPrefixOf)
import qualified Data.Map as Map
@@ -22,15 +18,25 @@ infixl 8 .$
(.$) :: (a -> b) -> a -> b
(.$) a b = a b
+dup :: t -> (t, t)
dup a = (a, a)
+
+branch :: (t -> t1) -> (t -> t2) -> t -> (t1, t2)
branch f g a = (f a, g a)
+
+swap :: (t, t1) -> (t1, t)
swap (a, b) = (b, a)
+bool :: t -> t -> Bool -> t
bool a b c = if c then a else b
-- Test eithers.
+
+left :: Either a b -> Bool
left (Left _) = True
left _ = False
+
+right :: Either a b -> Bool
right (Right _) = True
right _ = False
@@ -50,6 +56,7 @@ intRead = safeRead
-- Conversions.
+boolM :: Bool -> Maybe ()
boolM = bool (Just ()) Nothing
eitherToMaybe :: Either a b -> Maybe b
@@ -65,13 +72,19 @@ safeList :: ([a] -> b) -> [a] -> Maybe b
safeList _ [] = Nothing
safeList f xs = Just $ f xs
+safeHead :: [a] -> Maybe a
safeHead = safeList head
+
+safeLast :: [a] -> Maybe a
safeLast = safeList last
+withReverse :: ([a1] -> [a]) -> [a1] -> [a]
withReverse f = reverse . f . reverse
+trimWith :: (a -> Bool) -> [a] -> [a]
trimWith f = withReverse (dropWhile f) . dropWhile f
+snoc :: [a] -> a -> [a]
snoc a b = a ++ [b]
split :: Eq a => a -> [a] -> [[a]]
@@ -95,30 +108,50 @@ splitsWith n h =
-------[ map utilities ]-------------------------------------------------------
+(<->) :: Ord k => k -> a -> Map.Map k a -> Map.Map k a
(<->) a b c = Map.insert a b c
+(<--) :: Ord k => k -> a -> Map.Map k a
(<--) a b = Map.insert a b Map.empty
-------[ text manipulation ]---------------------------------------------------
+normalCase :: String -> String
+normalCase [] = []
normalCase (x:xs) = toUpper x : map toLower xs
-upperCase = map toUpper
-lowerCase = map toLower
+
+upperCase :: String -> String
+upperCase = map toUpper
+
+lowerCase :: String -> String
+lowerCase = map toLower
-- Trim all heading and trailing whitespace.
+
+trim :: String -> String
trim = trimWith (`elem` " \t\n\r")
-- ShowS functions.
-ss = showString
-intersperseS c [] = id
-intersperseS c [s] = s
+ss :: String -> String -> String
+ss = showString
+
+intersperseS :: (String -> String) -> [String -> String] -> String -> String
+intersperseS _ [] = id
+intersperseS _ [s] = s
intersperseS c xs = foldl1 (\a -> ((a.c).)) xs
-concatS = foldl (.) id
-concatMapS f = concatS . map f
-unlinesS = concatMapS (. ss "\n")
-eolS = ss "\n"
+concatS :: [String -> String] -> String -> String
+concatS = foldl (.) id
+
+concatMapS :: (a -> String -> String) -> [a] -> String -> String
+concatMapS f = concatS . map f
+
+unlinesS :: [String -> String] -> String -> String
+unlinesS = concatMapS (. ss "\n")
+
+eolS :: String -> String
+eolS = ss "\n"
-------[ second arity functor ]------------------------------------------------
@@ -138,22 +171,33 @@ ifM :: Monad m => m Bool -> (a -> a) -> a -> m a
ifM t f g = t >>= (\b -> return $ if b then f g else g)
-- Thread a value through monadic expression.
+
+constM :: Monad m => b -> m a -> m b
constM c = (>> return c)
-------[ parsec extensions ]---------------------------------------------------
-- Helper function to quickly apply a parser.
+(@@) :: GenParser Char () a -> String -> Maybe a
(@@) p b = either (const Nothing) Just $ parse (p <* eof) "" b
+
+(@!) :: GenParser Char () a -> String -> Either ParseError a
(@!) p b = parse (p <* eof) "" b
-- Apply a parser for a minimum of `n' times.
+
+pMin :: Int -> GenParser tok st a -> GenParser tok st [a]
pMin n p = (++) <$> count n p <*> many p
-- Apply a parser for a maximum of `n' times.
+
+pMax :: Int -> GenParser tok st a -> GenParser tok st [a]
pMax n p | n <= 0 = return []
| otherwise = option [] $ liftM2 (:) p (pMax (n-1) p)
-- Apply a parser for a minimum of `n' and a maximum of 'm' times.
+
+pRange :: Int -> Int -> GenParser tok st a -> GenParser tok st [a]
pRange n m p = liftM2 (++) (count n p) (pMax (m-n) p)
-- Option parser with maybe result.
@@ -162,11 +206,13 @@ pMaybe = option Nothing . liftM Just
-------[ time utils ]----------------------------------------------------------
+later :: Integer -> IO LocalTime
later howlong = do
zone <- getCurrentTimeZone
time <- liftM (addUTCTime $ fromInteger howlong) getCurrentTime
return $ utcToLocalTime zone time
+now :: IO LocalTime
now = later 0
-------[ concurrency utils ]---------------------------------------------------
@@ -2,7 +2,6 @@ module Network.Orchid.Core.Format where
import Data.ByteString.Lazy (ByteString)
import Data.FileStore (FileStore)
-import Network.Protocol.Uri (URI)
-- Formats produce proper UTF-8 text or binary docs. (TODO: ascii for tex?)
data Output =
Oops, something went wrong.

0 comments on commit 7c9a855

Please sign in to comment.