i trying expand (or trying find out whether it's possible expand) function type signature goes limits of knowledge, because of libraries i'm using expose quite polymorphic types , apis, more polymorphic.
i'm using persistent , hsqml, both libraries having pretty hairy types @ moments, @ least me.
i need wrap persistent entities hsqml "proxy" objects exposed qml (javascript basically). purpose made myself helper, called getstandardclassmembers. use so:
instance defaultclass (entity project) classmembers = getstandardclassmembers [ ("name", projectname), ("hascustomicon", text . not . bs.null . projecticon), ("hasdev", projecthasdev), -- todo bool string, ugly.. ("hasuat", projecthasuat), ("hasstaging", projecthasstage), ("hasprod", projecthasprod) ] [] the definition of getstandardclassmembers there. define javascript object members specify, , calls haskell functions give implement members of js object.
that's pretty nice there 'but'. function in second position in pair must return text. here see, first function, should rather return bool. ideally make type signature of getstandardclassmembers take type more polymorphic not require that second function returns text. , again don't know if it's possible, decided give shot.
so add rankntypes massive list of language extensions file (i'm kind of forced due libraries chose, otherwise wonderful).
and change:
getstandardclassmembers :: (marshal tr, tobackendkey sqlbackend record, typeable record, marshalmode tr icanreturnto () ~ yes) => [(string, record -> tr)] -> [(string, objref (entity record) -> maybe int)] -> [member (getobjtype (objref (entity record)))] to:
getstandardclassmembers :: (marshal tr, tobackendkey sqlbackend record, typeable record, marshalmode tr icanreturnto () ~ yes) => [(string, forall tr. record -> tr)] -> [(string, objref (entity record) -> maybe int)] -> [member (getobjtype (objref (entity record)))] (so added forall tr.) , get:
illegal polymorphic or qualified type: forall tr. record -> tr perhaps intended use impredicativetypes now know enough these things know enabling impredicativetypes not idea. plus if enable it, doesn't work either.
is want achievable or should give rest , thankful works @ pretty messy type signatures , language extension collections?
edit right fix forget helper , go basics using hsqml basic api. otherwise i'm still curious whether possible or not.
i think basic problem trying put values of different types in 1 list. impredicativetypes doesn't allow in way need. existential types work wrapper, think they're overkill well.
instead, suggest changing inserting tuples inserting same type, based on how going use tuples. looking @ linked code see
\(name, f) -> defpropertyconst name (return . f . entityval . fromobjref) as function use on tuples actually need them. why not define global function that?
stdmember name f = defpropertyconst name (return . f . entityval . fromobjref) (the name suggestion; might want shorter or operator.)
then change getstandardclassmembers take list of such values first argument, , similar second.
assuming there no more type subtleties, should able write
instance defaultclass (entity project) classmembers = getstandardclassmembers [ stdmember "name" projectname, stdmember "hascustomicon" $ text . not . bs.null . projecticon, stdmember "hasdev" projecthasdev, -- todo bool string, ugly.. stdmember "hasuat" projecthasuat, stdmember "hasstaging" projecthasstage, stdmember "hasprod" projecthasprod ] []
Comments
Post a Comment