将列表转换为int的函数?

phx*_*xxx 1 haskell

我有一个列表[2]我可以在Haskell中使用什么函数来提取2,所以我得到一个Int输出而不是列表?

谢谢

Ale*_*x R 6

最简单的答案是头部功能.

不幸的是,如果列表为空,这将产生运行时错误,所以最好像这样模式匹配:

case [2] of
  x:_ -> do something with x
  _   -> deal with the fact that the list is empty
Run Code Online (Sandbox Code Playgroud)