简体   繁体   中英

Using perfectly formatted input as list in Haskell

I'm doing a program in Haskell (on the Haskell platform), and I know I'm getting perfectly formatted inputs, so the input may look like

[ ['a'], ['b'], ['c'] ]

I want Haskell to be able to take this and use it as a list of it's own. And, I'd like this list to be over multiple lines, ie, I want this to also work:

[
  ['a'],
  ['b'],
  ['c']
]

I can parse this input, but I've been told there's a way to do this easily - this is supposed to be the 'trivial' part of the assignment, but I don't understand it.

read "[ ['a'], ['b'], ['c'] ]" :: [[Char]]

will return [ ['a'], ['b'], ['c'] ] . If you assign the result of read to a variable that can be inferred to be of type [[Char]] , you don't need the :: [[Char]] bit.

Haskell列表中有一个Read类的实例,这意味着您可以使用read函数有效地解析格式化为Haskell列表的字符串,这正是您所拥有的。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM