What is $sel in a Template Haskell Name? -


i'm calling th function, called createrecordsplice in following manner:

data user = user {userfoo :: string, userbar :: text} deriving (eq, show, generic) createrecordsplice "user" ''user ['userbar] "newuser" "nuser" 

notice record selector userbar passed single-quote.

now, in th function want check field names of user against userbar, i'm encountering strange field name contains $sel, due which, main logic failing work.

(common.testrecordsplices.userfoo,[common.testrecordsplices.$sel:userbar:user]) (common.testrecordsplices.userbar,[common.testrecordsplices.$sel:userbar:user]) 

what $sel:userbar:user , how 1 convert userbar $sel:userbar:user, or vice versa, without resorting string manipulation?

my th function:

createrecordsplice :: string -> name -> [name] -> string -> string -> q [dec] createrecordsplice sourceprefix record requiredfields newrectype targetprefix = reify record >>= \case   (tyconi (datad [] recordconstr [] knd constrs classes)) -> case constrs of     [(recc _ sourcefields)] ->       let newfields = dl.foldl'                       (\memo (fname, bang, ftype) ->                           -- output trace given above                          trace (show (namebase fname, namebase <$> requiredfields)) $                            if (fname `elem` requiredfields)                          (sourcetotargetname fname, bang, ftype):memo                          else memo                       ) [] sourcefields       runio $ putstrln (show newfields)       pure $ [datad [] (mkname newrectype) [] knd [recc (mkname newrectype) newfields] classes]     _ -> fail $ "creating record splices types multiple constructors (sum types), i.e. data x = y | z, not supported yet"       sourcetotargetname n = mkname $ targetprefix ++ (dl.drop (dl.length sourceprefix) (namebase n)) 


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -