From: Marc W. <mar...@gm...> - 2006-07-28 21:26:36
|
I've tried understanding what the BoundedList.hs module is all about but I couldn' get it completely -- This inductive approach gives the complexity O(n) on the number of instances -- and very short type checking times compared to an O(n\^2) implementation. Where is the difference between [a] and (BoundedList a Nxx)? Is it only used for BoundedString by now? (to prevent data loss when copying from char(10) to char(4)? Did I get it right that the internal representation is still an ordinary list ? (newtype BoundedList a n = BoundedList [a])? Looking at instance (Show a, Size n) => Show (BoundedList a n) where show l@(L xs) = show xs l@ is superfluous, isn't it? Marc |
From: Bjorn B. <bri...@cs...> - 2006-07-29 23:13:42
|
On Jul 28, 2006, at 2:26 PM, Marc Weber wrote: > I've tried understanding what the BoundedList.hs module is all =20 > about but > I couldn' get it completely > > -- This inductive approach gives the complexity O(n) on the number =20 > of instances > -- and very short type checking times compared to an O(n\^2) =20 > implementation. > > Where is the difference between [a] and (BoundedList a Nxx)? > Is it only used for BoundedString by now? > (to prevent data loss when copying from char(10) to char(4)? Yes, BoundedList is only used for BoundedString in HaskellDB. The =20 purpose of BoundedString is, as you guessed, to avoid string =20 truncation. For more information, see our Haskell Workshop paper, =20 http://haskelldb.sourceforge.net/haskelldb.pdf > Did I get it right that the internal representation is still an =20 > ordinary > list ? (newtype BoundedList a n =3D BoundedList [a])? Yes. BoundedList uses a phantom type to keep the string max length in =20= the type of the list. The internal representation is a normal list. > Looking at > > instance (Show a, Size n) =3D> Show (BoundedList a n) where > show l@(L xs) =3D show xs > > l@ is superfluous, isn't it? Yes. There are probably lots of unused bindings in the HaskellDB =20 code. I guess we should compile with -Wall and fix all the warnings. /Bj=F6rn |
From: Marc W. <mar...@gm...> - 2006-08-06 13:16:05
|
eg mysqlConnect is of type: mysqlConnect :: MonadIO m => MySQLOptions -> (Database -> m a) -> m a Typical usage looks like this, doesn't it? doSomething :: MonadIO m => (Database -> m a) -> m a -> IO () -- << main=do con <- mysqlConnect Options doSomething con .. Wouln't it be mucht clearer to use another typedef to write something like this ? newtype CConnection :: MonadIO m => (Database -> m a) -> m a doSomething :: CConnection -> IO () -- << much shorter and clearer main=do con <- mysqlConnect Options doSomething con .. The first C migt indicate that it's a "connected" connection (parameters have already been applied).. Or does this already exist? I'd like to provide a patch if you consider it useful Greetings Marc Weber |
From: Bjorn B. <bri...@cs...> - 2006-08-06 16:31:08
|
On Aug 6, 2006, at 5:15 PM, Marc Weber wrote: > eg mysqlConnect is of type: > mysqlConnect :: MonadIO m =3D> MySQLOptions -> (Database -> m a) -> m = a > > Typical usage looks like this, doesn't it? > > > doSomething :: MonadIO m =3D> (Database -> m a) -> m a -> IO () = -- << > main=3Ddo > con <- mysqlConnect Options > doSomething con .. > > Wouln't it be mucht clearer to use another typedef to write =20 > something like this ? > > > newtype CConnection :: MonadIO m =3D> (Database -> m a) -> m a > doSomething :: CConnection -> IO () -- << much shorter and = clearer > main=3Ddo > con <- mysqlConnect Options > doSomething con .. > > The first C migt indicate that it's a "connected" connection =20 > (parameters have already been applied).. > Or does this already exist? > > I'd like to provide a patch if you consider it useful > > Greetings > Marc Weber Hi Marc, I'm not sure that I completely understand your example. I think that =20 there is something wrong with the types. Here's how I think a typical application looks with the current types: options :: MysqlOptions options =3D ... doSomething :: Database -> IO () doSomething db =3D ... main :: IO () main =3D mysqlConnect options doSomething I probably misunderstood what you want to do though. /Bj=F6rn |
From: Marc W. <mar...@gm...> - 2006-08-09 08:02:56
|
I had/have some problems with types of haskelldb so I tried to add type annotations. I've used Select query mainly yet. Thus my code looks like this: con = mysqlConnect <params> doSomethinng con = con $ \db -> query db $ table <table> Then I wanted to add type annotations. Thus I took the type of mysqlConnect :: MonadIO m => MySQLOptions -> (Database -> m a) -> m a and removed the connection settings yielding mysqlConnect :: MonadIO m => (Database -> m a) -> m a which is very much to type/reead IMHO. That's why I proposed introducnig: newtype CConnection :: MonadIO m => (Database -> m a) -> m a I'm struggling here now: line 39 is equal to 56 line 39 works fine line 56 doesn't. Why? Isn't both a IO monad (because of the print statements) After commenting out 56 it compiles. module Modules.ObjectTree where import Debug.Trace import Data.FunctorM import DBUtils import qualified DB.VT.Ezcontentobject_tree as EOT import qualified DB.VT.Ezcontentobject as CO import Database.HaskellDB.HDBRec import Database.HaskellDB import Database.HaskellDB.Query as Q import Data.Tree import Monad import Control.Monad.Trans import Maybe import qualified List instance FunctorM Tree where fmapM f (Node a forest) = do a' <- f a forest' <- mapM (fmapM f) forest return $ Node a' forest' type ObjectTree a = Tree (Record a) truncTree 1 (Node a _) = Node a [] truncTree x (Node a forest) = Node a $ map (truncTree (x-1)) forest oT con = do print "blah" -- because of this we should have a simple IO Monad ? lookupField con (CO.name) (CO.ezcontentobject) (CO.xid) (constant (1 :: Int)) >>= print :: IO () -- <<<<<<<<<<<<<<<<<<<<<<<<< 39 return "blah" -- printObjectsAsTree :: MonadIO m => ((Database -> m a) -> m a) -> Int -> IO () printObjectsAsTree con startid= do --<<<<<<<<<<<<<<<< 4 print "test" root <- liftM head $ lRS (EOT.parent_node_id) (constant (startid :: Int)) print root --showRS root >>= putStrLn node <- po root node_show <- fmapM showRS node return $ drawTree node_show -- return "end" where lRS = lookupFieldRS con (EOT.ezcontentobject_tree) po root = let root_id = (root!(EOT.node_id) :: Int) in do print "dumm" -- IO Monad too ? print (root!(EOT.node_id)) lookupField con (CO.name) (CO.ezcontentobject) (CO.xid) (constant (1 :: Int)) >>= print -- <<<<<<<<<<<<<< 56 return $ Node root [] --childs <- lRS (EOT.parent_node_id) (constant root_id) --mapM_ (\r -> r!(EOT.node_id)) childs >>= print showRS r = do -- name <- lookupField con (CO.name) (CO.ezcontentobject) (CO.xid) (constant 1) >>= print return "ab" :: IO String --return $ (show $ r!node_id) ++ " (" ++ (fromJust name) ++ " )" ----------------------------------------------- || Preprocessing executables for dbez-0.0... || Building dbez-0.0... || Chasing modules from: db_ez.hs || [1 of 6] Skipping DBUtils ( DBUtils.hs, dist/build/db_ez/db_ez-tmp/DBUtils.o ) || [2 of 6] Skipping DB.VT.Ezcontentobject_tree ( DB/VT/Ezcontentobject_tree.hs, dist/build/db_ez/db_ez-tmp/DB/VT/Ezcontentobject_tree.o ) || [3 of 6] Skipping DB.VT.Ezcontentobject ( DB/VT/Ezcontentobject.hs, dist/build/db_ez/db_ez-tmp/DB/VT/Ezcontentobject.o ) || [4 of 6] Compiling Modules.ObjectTree ( Modules/ObjectTree.hs, dist/build/db_ez/db_ez-tmp/Modules/ObjectTree.o ) || Modules/ObjectTree.hs|43| 0: || Couldn't match `DB.VT.Ezcontentobject_tree.Contentobject_id' || against `DB.VT.Ezcontentobject.Contentclass_id' || Expected type: RecCons DB.VT.Ezcontentobject_tree.Contentobject_id || (Maybe Int) || vr || Inferred type: RecCons DB.VT.Ezcontentobject.Contentclass_id || Int || vr1 || When using functional dependencies to combine || Database.HaskellDB.Database.GetRec (RecCons f (Expr a) er) || (RecCons f a vr), || arising from the instance declaration at Imported from Database.HaskellDB.Database || Database.HaskellDB.Database.GetRec (RecCons DB.VT.Ezcontentobject_tree.Contentobject_id || (Expr (Maybe Int)) [...] || (RecCons DB.VT.Ezcontentobject_tree.Sort_order || (Expr (Maybe Int)) || RecNil)))))))))))))))) || (RecCons DB.VT.Ezcontentobject.Contentclass_id Int vr), arising from use of `lookupFieldRS' at Modules/ObjectTree.hs|52| 14-26 || When generalising the type(s) for `printObjectsAsTree' _______________________________________________ Haskell-Cafe mailing list Has...@ha... http://www.haskell.org/mailman/listinfo/haskell-cafe |
From: Marc W. <mar...@gm...> - 2006-08-11 11:05:35
|
I tracked it down. The problem was that I couldn't use the same con type for two different tables.. All the time I was only thinking about the return value.. which was IO () in either case The trick was to pass another con value for eaach table ;) Marc |