debugging - Haskell breaks my type when I call show/read -


i have defined new type in haskell code, takes list of lists of strings record. example might be
board{size=(4,7),pieces=[["oa","aa","aa"],["bbb","boo"],["occc","ccco","ooco"]]}

i've set derived instance of show , read. if input code above ghci, out put in, fine. however, if call show, get
"board {size = (4,7), pieces = [[\"oa\",\"aa\",\"aa\"],[\"bbb\",\"boo\"],[\"occc\",\"ccco\",\"ooco\"]]}"
speech marks fine, i've no idea why backslashes there. not allowed next speech marks or something? in case, totally breaks if try call read back. long error trying tell me none of strings data constructors - don't know why thinks are.

is there way round this?

given

> data board = board { size :: (int, int), pieces :: [[string]] } deriving (show, read) > let b = board{size=(4,7),pieces=[["oa","aa","aa"],["bbb","boo"],["occc","ccco","ooco"]]} 

the result of show b string

> show b "board {size = (4,7), pieces = [[\"oa\",\"aa\",\"aa\"],[\"bbb\",\"boo\"],[\"occc\",\"ccco\",\"ooco\"]]}" 

the quotes in string escaped when show-ing string. if output string instead you'll see doesn't contain \ characters.

> putstrln $ show b board {size = (4,7), pieces = [["oa","aa","aa"],["bbb","boo"],["occc","ccco","ooco"]]} 

the string produced show can read in again board read

> (read . show $ b) :: board board {size = (4,7), pieces = [["oa","aa","aa"],["bbb","boo"],["occc","ccco","ooco"]]} 

Comments

Popular posts from this blog

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

Ruby on Rails, ActiveRecord, Postgres, UTF-8 and ASCII-8BIT encodings -