Question about mkHsI
Closed this issue · 3 comments
Hi,
I like the new API, seem a lot more straightforward!
I'm looking at the writing side of things now, but I'm unsure what columns I need to supply for the mkHsI
function. I assumed it's just the 'W
columns, with the 'WD
columns being optional so given
data TTodoItem
instance Tabla TTodoItem where
type Database TTodoItem = TodoDb
type SchemaName TTodoItem = "todo"
type TableName TTodoItem = "todo_item"
type Cols TTodoItem =
[ 'Col "id" 'WD 'R O.PGUuid TodoItemId
, 'Col "title" 'W 'R O.PGText Text
, 'Col "created" 'WD 'R O.PGTimestamptz UTCTime
, 'Col "due" 'WD 'RN O.PGTimestamptz UTCTime
, 'Col "completed" 'WD 'RN O.PGTimestamptz UTCTime
]
I had expected this:
mkHsI (T :: T TTodoItem) $ \set_ -> hBuild
(set_ (C :: C "title") t) -- t :: Text
(set_ (C :: C "due") mDue) -- mDue :: (Maybe UTCTime)
to be sufficient.
However I get:
Couldn't match type ‘'[y,
Tagged (TC TTodoItem "due") (Maybe UTCTime),
Tagged (TC TTodoItem "title") Text]’
with ‘'[]’
arising from a functional dependency between:
constraint ‘HRevApp
'[]
'[Tagged (TC TTodoItem "due") (Maybe UTCTime),
Tagged (TC TTodoItem "title") Text, y,
Tagged (TC TTodoItem "due") (Maybe UTCTime),
Tagged (TC TTodoItem "title") Text]
'[Tagged (TC TTodoItem "due") (Maybe UTCTime),
Tagged (TC TTodoItem "title") Text]’
arising from a use of ‘hBuild’
instance ‘HRevApp '[] l2 l2’ at <no location info>
In the expression:
hBuild (set_ (C :: C "title") t) (set_ (C :: C "due") mDue)
In the second argument of ‘($)’, namely
‘\ set_
-> hBuild (set_ (C :: C "title") t) (set_ (C :: C "due") mDue)’
In the expression:
mkHsI (T :: T TTodoItem)
$ \ set_
-> hBuild (set_ (C :: C "title") t) (set_ (C :: C "due") mDue)
I haven't been able to work my way through the types to understand what this is telling me yet.
Cheers!
Actually just writing this down seems to have fixed it :-)
mkHsI (T :: T TTodoItem) $ \set_ -> hBuild
(set_ (C :: C "id") WDef)
(set_ (C :: C "title") t)
(set_ (C :: C "created") WDef)
(set_ (C :: C "due") (WVal mDue))
(set_ (C :: C "completed") WDef)
Maybe just a note in the docs about how to structure this?
I suspect it is reasonable to expect that the "defaultable" columns can be
left blank here. 'hBuild' doesn't work that way, but maybe some other
function can be written that sets those defaults to 'WDef'. I am not sure
if that is good, though, being explicit should make things less error
prone. I'll see if this can be written.
In any case: yes, docs are still missing about this.
On May 3, 2016 2:56 AM, "Ben Ford" notifications@github.com wrote:
Actually just writing this down seems to have fixed it :-)
mkHsI (T :: T TTodoItem) $ \set_ -> hBuild
(set_ (C :: C "id") WDef)
(set_ (C :: C "title") t)
(set_ (C :: C "created") WDef)
(set_ (C :: C "due") (WVal mDue))
(set_ (C :: C "completed") WDef)Maybe just a note in the docs about how to structure this?
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub
#3 (comment)
This API changed https://github.com/k0001/opaleye-sot/blob/6237966fe981caefed65d346ba2b374f456e46ac/src/lib/Opaleye/SOT/Internal.hs#L837-L897
By the way, the code is now compatible with GHC 8, and support for GHC 7.10.x has been dropped.