<p dir="ltr">You'd still have to handle the case that the Value is not what you expected. Otherwise you'll have a partial function (i.e. error in case of certain inputs). </p>
<p dir="ltr">So maybe you'd best use aeson directly (which spares you the GetValue instances as well). </p>
<p dir="ltr">getValue :: (FromJSON a) => Text -> Map Text a -> Maybe a</p>
<p dir="ltr">Best <br>
Jan <br>
P.S. There is no such thing as a stupid question. </p>
<br><div class="gmail_quote"><div dir="ltr">Baa <<a href="mailto:aquagnu@gmail.com">aquagnu@gmail.com</a>> schrieb am Di., 1. Aug. 2017, 13:02:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hello, Jan! I "remove" the question :)<br>
Problem was: reading of HTML form values, which can be any type and<br>
saving them in a map. I done it w/ `Map Text Value` (instead of previous<br>
`Map Text Text`). To get values from the map, I implemented class and<br>
several instances which returns values of different types, something<br>
like:<br>
<br>
class GetValue a where<br>
getValue :: Text -> Map Text Value -> a<br>
<br>
(promoting of `a` anywhere in the existing code needs big refactoring,<br>
so map's value is `::Value` but not `::a`). Cons is a need to implement<br>
N instances of `GetValue`: one per getting type.<br>
<br>
Anywhere, Jan, thanks for quick answer, I'm sorry for this stupid<br>
question.<br>
<br>
<br>
> Hi,<br>
><br>
> You don't know anything about your a's but that they have FromJSON<br>
> instances. That in turn means you can get values from aeson parsing<br>
> functions. Think parseJSON :: Value -> Parser a<br>
> Could you be more specific about the problem you try to solve?<br>
><br>
> Best<br>
> Jan<br>
><br>
> Baa <<a href="mailto:aquagnu@gmail.com" target="_blank">aquagnu@gmail.com</a>> schrieb am Di., 1. Aug. 2017, 10:32:<br>
><br>
> > Hello, List!<br>
> ><br>
> > I have, for example, function with signature like<br>
> ><br>
> > fn :: FromJSON a => Map Text a -> BlahBlah<br>
> ><br>
> > and I want to treat this `a` as String (or `Text`), to read it with<br>
> > `readMaybe`. Am I right that it's impossible? I get error about<br>
> > "...a is rigid type and could not be matched with Text...". But<br>
> > `Text` is `FromJSON` instance. Is it possible to do it (cast,<br>
> > convert, unwrap, etc)?<br>
> ><br>
> > The problem's source is that early I worked with `Text` values only<br>
> > (getting from HTML form) but now they become any type: int's,<br>
> > bool's, etc).<br>
> ><br>
> > ===<br>
> > Best regards,<br>
> > Paul<br>
> > _______________________________________________<br>
> > Beginners mailing list<br>
> > <a href="mailto:Beginners@haskell.org" target="_blank">Beginners@haskell.org</a><br>
> > <a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners</a><br>
> ><br>
<br>
_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org" target="_blank">Beginners@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners</a><br>
</blockquote></div>