Haskell class functions: very confusing error -
i have confusing error in piece of code. using data.aeson package. don't think bug of package.
class toarrayformat getobjects :: (tojson b) => -> b toarrayformat :: -> value toarrayformat = tojson $ getobjects this piece of code fail compile error message :
not deduce (tojson s0) arising use of ‘tojson’ context (toarrayformat a) bound class declaration ‘toarrayformat’ @ <interactive>:(103,1)-(108,43) type variable ‘s0’ ambiguous in expression: tojson in expression: tojson $ getobjects in equation ‘toarrayformat’: toarrayformat = tojson $ getobjects i'm confused now. getobjects returns tojson b instance can consumed tojson in toarrayformat. can't deduce instance of b getobjects definition? why tojson s0 ambiguous?
the key part:
the type variable ‘s0’ ambiguous note tojson has type:
tojson :: tojson b => b -> value also, declaration:
getobjects :: (tojson b) => -> b says getobjects can convert a any type b in tojson class. instance, if blah value of type a, legally ask for:
getobjects blah :: int getobjects blah :: string getobjects blah :: char and convert blah int, string or char since of in tojson class. that's not had in mind, nor getobjects function does.
to understand error message, problem in expression tojson $ getobjects a, ghc doesn't know how type getobjects b - member of tojson class should - int?, string?, char?, other type?
you specify concrete type this:
toarrayformat = tojson $ (getobjects :: char) but, i've said, that's not had in mind.
Comments
Post a Comment