What is the correct way to write a rich Haskell show function?

My understanding of the correct implementation of Haskell Show, and Readis, that read.showshould be identical. If true, then it Readshould either be able to perform fairly dirty parsing of strings, or it Showshould provide fairly limited functionality (from the user's point of view).

In this case read.show == id, and if so, what is the accepted practice of Haskell - for naming functions and calling - for richer (string) representations of values?

+4
source share
1 answer

, , show , Haskell - , Haskell .

, read . show . , ,

read (show x) == x

(==) - , Eq. , Data.Set.Set, , (BST). show

fromList [1,2,3,4,6,7]

read , , BST, , == . , () .

"" fromSomeTransparentType value.

, , show - " " , . , , , , . , , :

data Exp = Add Exp Exp | ...
instance Show Exp where
   show (Add e1 e2) = "(" ++ show e1 ++ ", " ++ show e2 ++ ")"

"" show . read == id . -, read . -, , read , . : ( AJFarmar )

show (read "Just (((6)))") = "Just 6"
+5

Source: https://habr.com/ru/post/1607002/


All Articles