packages feed

DSH 0.7 → 0.7.1

raw patch · 5 files changed

+36/−24 lines, 5 files

Files

DSH.cabal view
@@ -1,14 +1,7 @@ Name:                DSH-Version:             0.7+Version:             0.7.1 Synopsis:            Database Supported Haskell Description:-  Note that DSH-0.7 is the very first, experimental release that is intended-  to be used with monad comprehensions (a Haskell extension available in-  GHC-7.2). For a currently stable version that implements comprehensions-  using quasiquoting please download DSH-0.6. The experimental changes in this-  version only affect the comprehension notation, the behaviour of the-  supported combinators is not affected.-  .   This is a Haskell library for database-supported program execution. Using   this library a relational database management system (RDBMS) can be used as   a coprocessor for the Haskell programming language, especially for those
examples/Example01.hs view
@@ -1,6 +1,3 @@--- This example was taken from the paper called "Comprehensive Comprehensions"--- by Phil Wadler and Simon Peyton Jones- {-# LANGUAGE MonadComprehensions, RebindableSyntax, ViewPatterns #-}  module Main where@@ -14,16 +11,23 @@ ints :: Q [Integer] ints = toQ [1 .. 10] -query :: Q [(Integer,Integer)]-query = [ tuple (i1, i2)-        | i1 <- ints-        , i2 <- ints-        ]+query1 :: Q [(Integer,Integer)]+query1 =  [ tuple (i1,i2)+          | i1 <- ints+          , i2 <- ints+          ] +query2 :: Q [(Integer,Integer)]+query2 =  [ tuple (i1,i2)+          | (view -> (i1,i2)) <- query1+          , i1 == i2+          ]+           getConn :: IO Connection getConn = connectPostgreSQL "user = 'giorgidz' password = '' host = 'localhost' dbname = 'giorgidz'" +runQ :: (Show a,QA a) => Q a -> IO ()+runQ q = getConn P.>>= \conn -> (fromQ conn q P.>>= P.print) P.>> disconnect conn+ main :: IO ()-main = -  getConn          P.>>= \conn ->-  fromQ conn query P.>>= P.print+main = (runQ ints) P.>> (runQ query1) P.>> (runQ query2)
src/Database/DSH.hs view
@@ -98,4 +98,5 @@   , either   , return   , (>>=)+  , (>>)   )
src/Database/DSH/CSV.hs view
@@ -1,6 +1,6 @@-{-# LANGUAGE TemplateHaskell, RelaxedPolyRec, OverloadedStrings #-}+{-# LANGUAGE TemplateHaskell, OverloadedStrings #-} -module Database.DSH.CSV (csvImport, csvExport) where+module Database.DSH.CSV (csvImport, csvExport, csvExportHandle, csvExportStdout) where  import Database.DSH.Data import Database.DSH.Impossible@@ -10,8 +10,17 @@ import qualified Data.Text as T import qualified Data.Text.IO as T -csvExport :: (TA a) => FilePath -> [a] -> IO ()-csvExport file as = T.writeFile file csvContent+import qualified System.IO as IO+import System.IO (Handle)++csvExport :: (QA a) => FilePath -> [a] -> IO ()+csvExport file as = IO.withFile file IO.WriteMode (\handle -> csvExportHandle handle as)++csvExportStdout :: (QA a) => [a] -> IO ()+csvExportStdout = csvExportHandle IO.stdout++csvExportHandle :: (QA a) => Handle -> [a] -> IO ()+csvExportHandle handle as = T.hPutStr handle csvContent   where csvContent :: Text         csvContent = T.unlines (map (toRow . toNorm) as) @@ -26,7 +35,7 @@          toRow :: Norm -> Text         toRow e = case e of-                    ListN _ _       -> $impossible+                    ListN _ _       -> "Nesting"                     UnitN _         -> quote "()"                     BoolN b _       -> quote (T.pack (show b))                     CharN c _       -> quote (escape (T.singleton c))
src/Database/DSH/Combinators.hs view
@@ -334,9 +334,14 @@ (>>=) :: (QA a, QA b) => Q [a] -> (Q a -> Q [b]) -> Q [b] (>>=) ma f = concatMap f ma +(>>) :: (QA a, QA b) => Q [a] -> Q [b] -> Q [b]+(>>) ma mb = concatMap (\_ -> mb) ma+ mzip :: (QA a, QA b) => Q [a] -> Q [b] -> Q [(a,b)] mzip = zip +guard :: Q Bool -> Q [()]+guard c = cond c (singleton unit) nil  infixl 9 !! infixr 5 ><, <|, |>