Whilst attempting to get some character conversion happening I wondered what the solution for this would be if I could not perform it with pure functions. For example, if I needed to convert from some encoding that the Data.Text.Encoding module does not automatically support.
So, I am attempting to write bindings using the servant-client libraries for a REST API that is not within my control.
So, I am quite happy to go and write a JsonIso8859 data type and add Accept/MimeUnrender instances for it.
My attempt so far was to convert the data to UTF-8 before feeding it into Aeson's decode machinery.
To do this for the encoding above I can use Data.Text.Encoding, if however I had a more fruity thing to decode right now I can only see the Text.ICU.Convert package. Okay, seems fairly easy to use.
Since it is a set of bindings to an external library that requires access to the filesystem the initial call to create a converter is of the following type:
open::String ->MaybeBool ->IOConverter
So, my problem is that I am not experienced enough right now to understand how I can get this working in the context of MimeUnrender, which is not within IO.
I could create a converter in my main program and pass it into the client somehow.
This is complicated by the fact that the ClientM definition is currently not able to accept (I think) user-specified data/context, it is two readers wrapping the manager and base url. So, I'm not sure how I would pass it in without creating my own ClientM that was more general. There may be ways, I'm still learning.
Even if I could pass a converter I create beforehand into the client I have absolutely no idea/control over how the MimeUnrender function gets called so I have no way of passing it in at that point anyway.
What would be nice (but I don't think works) is if I could create a partially applied MimeUnrender function that I can then use in the MimeUnrender instance.....but I have a feeling this is not possible or I just don't know how to accomplish it.
So, as I said, this is not a real problem for me right now but I am really interested to know how one would go about solving this.