I am trying to write instance of Read class to read an input as string as follow:
"1 3 -
- 2 3
- - 5"
Convert it into [[Maybe Int]]
“-” will be translated into Nothing
“3” will be Just 3
"('a',3) - ('b',7)
('c',5) ('e',0) -
('d',9) - ('h',8)"
Convert it into [[Maybe (Char,Int)]]
“-” will be translated into Nothing
“(‘a’,3)” will be Just ('a',3)
I tried to write them by handling with List of Char, but it takes a lot of work. Do you have any suggestion? Sorry, I am quite new to Haskell, so I ask you that question. 🙁
If you got rid of the
-entries, you could do this very quickly asOr define it as a function
Which you can use thus:
but you may find it easier to do
So you can just type
But what about keeping the
-? You’ll have to use a Maybe data type, to represent not having a value for certain points in your list; we can use-as shorthand forNothingandaas shorthand forJust a.I should warn you that that code is fragile if your data could possibly be
'-', but perhaps it can’t.Then we can have
So now we can do