-
Notifications
You must be signed in to change notification settings - Fork 66
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Remove instance PFromJSVal a => PFromJSVal (Maybe a) #46
Comments
IMHO, in the case of null, an exception should be thrown. See #24 . It is a bit strange to have this instance of maybe around, but it's also pretty darn convenient. You might be interested in my definition for Maybe in this PR: https://github.com/ghcjs/ghcjs-base/pull/34/files#diff-e09b67a14d374b52d6408c4ebcb9b630R7 . It ensures that you don't attempt to marshal |
Thanks, you PR looks interesting. In my particular case I do not want to fiddle with exceptions due to performance considerations and their uselessness (again, in my case). The idea is that I have some performance-critical part where I need to work with js objects transferred through network, and I do not want to transform them into Haskell representation (a lot of arrays there). So I have decided to only access their properties in pure code, so I need a lot of pure Again, sometimes I cannot write Lastly, IMHO the idea of |
So, it's only the instance for your enum type would throw exceptions for null. This seems like a valid thing to do for me. The instance for I'm starting to lean towards not having an instance for For now, in your particular case, I'd recommend using a newtype wrapper around |
The main reason I do not want to use exceptions is that I expect my js values to be null - for a program it is not an exceptional behavior. I am anyway using my own forked ghcjs-base, because of |
Please, remove instance PFromJSVal a => PFromJSVal (Maybe a) from GHCJS.Marshal.Pure
This is especially important for enum types. Let say, I want map a string property of JS object onto dedicated Haskell data type:
But current implementation does not make a lot of sense, because if
a
is an instance ofPFromJSVal
, one should probably take into account that underlying JS object may be null.The text was updated successfully, but these errors were encountered: