Does Elm have an equivalent of Haskell's “Read”

感情迁移 提交于 2019-12-01 18:01:53

My understanding is that Elm—not having typeclasses—cannot easily have a polymorphic version of read or fromJSON. I also do not believe it has any good facilities for generic programming, so implementing something akin to deriving or OCaml's with would be difficult as well.

Unfortunately, this means your best bet is to write one-off functions for serializing and deserializing the various types you use. You could use aeson on the Haskell side and then write functions to/from JSON using Elm's JSON library.

Another option may be to try reusing the code produced by Haskell's deriving Read and porting it to Elm. However, this might be more work than it's worth, and I am not sure how to go about it, exactly.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!