twitter bootstrap - Haskell Equality Constraint -


i'm trying build bootstrap 3 compatibility yesod. however, doing making "renderbootstrap3" function impossible because can't add class inputs. so, i've opted making bootstrap versions of fields in form.fields. idea can clone normal fields add class declaration in attributes array. here relevant code:

import qualified yesod.form.fields f  injectclass :: (text -> text -> [(text,text)] -> either text -> bool -> widgett (handlersite m) io ()            text -> text -> [(text,text)] -> either text -> bool -> widgett (handlersite m) io () injectclass f b attrs d e = f b attrs d e  textfield :: (monad m, rendermessage (handlersite m) formmessage) => field m text textfield = addinputclass f.textfield  addinputclass :: (monad m, rendermessage (handlersite m) formmessage) => field m -> field m addinputclass f = f { fieldview = (injectclass $ fieldview f)} 

so, intention take normal version of text field , use record syntax modify fieldview method. method should replaced 1 identical except addition of class attribute. not yet implemented in code above. like:

injectclass f b attrs d e = f b (("class", "form-control") : attrs) d e 

anyway, problem original code won't compile. equality constraint error:

could not deduce (handlersite m0 ~ handlersite m) context (monad m,                   rendermessage (handlersite m) formmessage)   bound type signature              addinputclass :: (monad m,                                rendermessage (handlersite m) formmessage) =>                               field m -> field m   @ field/bootstrap.hs:27:18-95 nb: `handlersite' type function, , may not injective type variable `m0' ambiguous possible fix: add type signature fixes these type variable(s) expected type: fieldviewfunc m   actual type: text                -> text                -> [(text, text)]                -> either text                -> bool                -> widgett (handlersite m0) io () in `fieldview' field of record in expression: f {fieldview = (injectclass $ fieldview f)} in equation `addinputclass':     addinputclass f = f {fieldview = (injectclass $ fieldview f)} 

notice fieldviewfunc m a defined as

type fieldviewfunc m     = text -- ^ id    -> text -- ^ name    -> [(text, text)] -- ^ attributes    -> either text -- ^ either (invalid text) or (legitimate result)    -> bool -- ^ required?    -> widgett (handlersite m) io () 

so, i'm not far off. problem (i think) isn't recoginizing injectclass doesn't change monad. however, should obvious compiler. type signature injectclass clear this. i'm looking need satisfy ghc. help, , let me know if can more clear.

ah, type families , non-injectivity.

here's what's going on: trying type-check

f { fieldview = (injectclass $ fieldview f)} 

the problem not injectclass might change m is. problem doesn't know m is. input, fieldview f , context, setting fieldview field of f, both tell handlersite m is, , simple fact can't work out m there. it's if had following:

type family f type instance f int = bool type instance f char = bool 

now trying pass f int f char expected succeed, because they're both bool. hence, trying pass handlersite m0 handlersite m expected might succeed, if m not m0! hence, type checker can't sure m0 supposed same m, ambiguous type error.

moreover, can't resolve ambiguity manual annotations, since you'll run same problem: you'll telling type checker handlersite m should be, knows.

can remove handlersite m type signature of injectclass entirely, replacing ordinary type variable h, say? ought solve problem, i'm not sure if create new ones.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -