From: Colin P. A. <co...@co...> - 2009-09-15 10:20:30
|
I have the following code: -- | Get list of all top-level galleries from database topLevelGalleries :: DB.Database -> IO [Gallery] topLevelGalleries db = do let q = do t <- DB.table galleryTable DB.restrict (DB.isNull $ t DB.! parentGalleryName) return t rs <- DB.query db q return $ map newGallery rs --newGallery :: DB.Record vr -> Gallery newGallery rec = Gallery (rec DB.! galleryName) (rec DB.! parentGalleryName) (rec DB.! readImageCapabilityName) (rec DB.! uploadImageCapabilityName) (rec DB.! administerGalleryCapabilityName) The reason the signature for newGallery is commented out is that it is very hard to write. I fired up ghci and did a :t newGallery. I got: newGallery :: (Database.HaskellDB.HDBRec.Select (Database.HaskellDB.Query.Attr Database.GalleryTable.GalleryName String) r String, Database.HaskellDB.HDBRec.Select (Database.HaskellDB.Query.Attr Database.GalleryTable.ParentGalleryName (Maybe String)) r (Maybe String), Database.HaskellDB.HDBRec.Select (Database.HaskellDB.Query.Attr Database.GalleryTable.ReadImageCapabilityName String) r String, Database.HaskellDB.HDBRec.Select (Database.HaskellDB.Query.Attr Database.GalleryTable.UploadImageCapabilityName String) r String, Database.HaskellDB.HDBRec.Select (Database.HaskellDB.Query.Attr Database.GalleryTable.AdministerGalleryCapabilityName String) r String) => r -> Dragonfly.ImageGallery.ImageGallery.Gallery Well, that's a bit of a mouthful. I don't really want to type that in. I would have hoped that somwhere there was a type definition generated from this from the DBInfo, but I can't find it. Any suggestions as to where to look? -- Colin Adams Preston Lancashire |
From: Justin B. <jgb...@gm...> - 2009-09-15 15:13:23
|
Colin, HaskellDB is going to give you some complicated type signatures - its a side-effect of using the type system to enforce things like field membership. You could just do the record selection in the topLevelGalleries function: > return $ map (\rec -> newGallery (rec DB.! galleryName) (rec DB.! parentGalleryName) (rec DB.! readImageCapabilityName) (rec DB.! uploadImageCapabilityName) (rec DB.! administerGalleryCapabilityName)) rs > newGallery name parent read upload admin = Gallery name parent read upload admin On Tue, Sep 15, 2009 at 3:20 AM, Colin Paul Adams <co...@co...> wrote: > I have the following code: > > > -- | Get list of all top-level galleries from database > topLevelGalleries :: DB.Database -> IO [Gallery] > topLevelGalleries db = do > let q = do > t <- DB.table galleryTable > DB.restrict (DB.isNull $ t DB.! parentGalleryName) > return t > rs <- DB.query db q > return $ map newGallery rs > > --newGallery :: DB.Record vr -> Gallery > newGallery rec = Gallery (rec DB.! galleryName) (rec DB.! parentGalleryName) (rec DB.! readImageCapabilityName) (rec DB.! uploadImageCapabilityName) (rec DB.! administerGalleryCapabilityName) > > > The reason the signature for newGallery is commented out is that it is > very hard to write. I fired up ghci and did a :t newGallery. I got: > > newGallery > :: (Database.HaskellDB.HDBRec.Select > (Database.HaskellDB.Query.Attr > Database.GalleryTable.GalleryName String) > r > String, > Database.HaskellDB.HDBRec.Select > (Database.HaskellDB.Query.Attr > Database.GalleryTable.ParentGalleryName (Maybe String)) > r > (Maybe String), > Database.HaskellDB.HDBRec.Select > (Database.HaskellDB.Query.Attr > Database.GalleryTable.ReadImageCapabilityName String) > r > String, > Database.HaskellDB.HDBRec.Select > (Database.HaskellDB.Query.Attr > Database.GalleryTable.UploadImageCapabilityName String) > r > String, > Database.HaskellDB.HDBRec.Select > (Database.HaskellDB.Query.Attr > Database.GalleryTable.AdministerGalleryCapabilityName String) > r > String) => > r -> Dragonfly.ImageGallery.ImageGallery.Gallery > > Well, that's a bit of a mouthful. I don't really want to type that in. > > I would have hoped that somwhere there was a type definition generated > from this from the DBInfo, but I can't find it. Any suggestions as to > where to look? > -- > Colin Adams > Preston Lancashire > > ------------------------------------------------------------------------------ > Come build with us! The BlackBerry® Developer Conference in SF, CA > is the only developer event you need to attend this year. Jumpstart your > developing skills, take BlackBerry mobile applications to market and stay > ahead of the curve. Join us from November 9-12, 2009. Register now! > http://p.sf.net/sfu/devconf > _______________________________________________ > Haskelldb-users mailing list > Has...@li... > https://lists.sourceforge.net/lists/listinfo/haskelldb-users > |
From: Colin P. A. <co...@co...> - 2009-10-12 05:47:40
|
>>>>> "Justin" == Justin Bailey <jgb...@gm...> writes: Justin> Colin, HaskellDB is going to give you some complicated Justin> type signatures - its a side-effect of using the type Justin> system to enforce things like field membership. Would it be possible to exploit context synonyms (see http://martijn.van.steenbergen.nl/journal/2009/10/11/context-synonyms/) to automatically generate more readable (and therefore writeable) signatures? -- Colin Adams Preston Lancashire |
From: Justin B. <jgb...@gm...> - 2009-10-12 15:44:16
|
That is really slick and it sounds like it would work. UndecideableInstances are already allowed anyways. On Sun, Oct 11, 2009 at 10:47 PM, Colin Paul Adams <co...@co...> wrote: >>>>>> "Justin" == Justin Bailey <jgb...@gm...> writes: > > Justin> Colin, HaskellDB is going to give you some complicated > Justin> type signatures - its a side-effect of using the type > Justin> system to enforce things like field membership. > > Would it be possible to exploit context synonyms (see > http://martijn.van.steenbergen.nl/journal/2009/10/11/context-synonyms/) > to automatically generate more readable (and therefore writeable) signatures? > -- > Colin Adams > Preston Lancashire > |