最佳答案
为什么 Prelude.read 的类型是
read :: Read a => String -> a
而不是返回 Maybe值?
read :: Read a => String -> Maybe a
Since the string might fail to be parseable Haskell, wouldn't the latter be be more natural?
或者甚至是一个 Either String a,如果它不解析,Left将包含原始字符串,如果它解析,Right将包含结果?
编辑:
我不是想让别人为我写一个相应的包装。只是想确保这样做是安全的。