Hello,
I have a naive question (my Haskell is rusty, so bear with me). I have a strict Data.Map.Map type like Map OsPath MyType. (The MyType is just a record I have in my program and not material to this discussion.) Anyway, I want to write this map as a JSON value to disk, like foo.json. However I get an error from Data.Aeson about how there is no ToJSONKey instance for the OsPath type.
I have two questions:
- Would it make sense for this library to add a
ToJSONKey instance for OsPath? IIUC this library saves the raw bytes into OsPath (not caring about encoding), while still taking care to note path separators. So theoretically it appears to me that we could print out these raw bytes (and path separators) as some sort of compound JSON value. It definitely won't be as pretty as writing a basic String (e.g. FilePath) value, but at least it's something...?
- Assuming the above is a bad idea, what is the recommended workaround? In particular my application reads files from disk, and I am basically saving the path from which the file was read as an
OsPath (and parsing the contents as a MyType). I just want to use OsPath everywhere because I really enjoy the fact that the type system makes it clear how it's not just a String equivalent (which I've always disliked about FilePath). Any specific guidance here would be appreciated.
Thanks!
Hello,
I have a naive question (my Haskell is rusty, so bear with me). I have a strict Data.Map.Map type like
Map OsPath MyType. (TheMyTypeis just a record I have in my program and not material to this discussion.) Anyway, I want to write this map as a JSON value to disk, likefoo.json. However I get an error from Data.Aeson about how there is noToJSONKeyinstance for theOsPathtype.I have two questions:
ToJSONKeyinstance forOsPath? IIUC this library saves the raw bytes into OsPath (not caring about encoding), while still taking care to note path separators. So theoretically it appears to me that we could print out these raw bytes (and path separators) as some sort of compound JSON value. It definitely won't be as pretty as writing a basicString(e.g.FilePath) value, but at least it's something...?OsPath(and parsing the contents as aMyType). I just want to use OsPath everywhere because I really enjoy the fact that the type system makes it clear how it's not just aStringequivalent (which I've always disliked aboutFilePath). Any specific guidance here would be appreciated.Thanks!