Haskell 如何转换[[Char]]->;哈斯克尔的查尔?

Haskell 如何转换[[Char]]->;哈斯克尔的查尔?,haskell,types,compiler-errors,type-conversion,Haskell,Types,Compiler Errors,Type Conversion,我试图以一种好的文本格式输出一系列城市,每一个都从一行开始。每个数据段用逗号分隔。但是我得到了一个错误,无法将预期类型Char与实际类型[[Char]]]匹配。比如说 (“纽约”(1,1),[5,4,3,2]) 将输出为: New York, (1,1), [5, 4, 3, 2] 以下是我目前的代码: type Name=String 类型坐标=(Int,Int) 类型Pop=Int 键入TotalPop=[Pop] 输入Place=(名称、坐标、TotalPop) 地点::[地点] 地点

我试图以一种好的文本格式输出一系列城市,每一个都从一行开始。每个数据段用逗号分隔。但是我得到了一个错误,
无法将预期类型Char与实际类型[[Char]]]
匹配。比如说

(“纽约”(1,1),[5,4,3,2])
将输出为:

New York, (1,1), [5, 4, 3, 2]
以下是我目前的代码:

type Name=String
类型坐标=(Int,Int)
类型Pop=Int
键入TotalPop=[Pop]
输入Place=(名称、坐标、TotalPop)
地点::[地点]
地点=[(“纽约”,(1,1),[5,4,3,2]),
(“华盛顿特区”(1,1),[4,3,2,1]),
(《洛杉矶》,(3,3),[7,6,5,4])]
placesToString::[Place]->IO()
placesToString ps=putStrLn(showPlaces ps)
展厅::[Place]->字符串
showPlaces ps=[showPlace p++“\n”| p我使用它工作(interlate类似于其他语言中的Array.join)

导入数据列表(插入)
展厅::[Place]->字符串

showPlaces ps=interlate“\n”[showData d|d什么是
showcity
?完整的错误文本也会有帮助。我们不应该猜测错误发生在哪一行。也许您需要在两个列表理解之后
concat
,例如
…=concat[showPlace p++“\n”\124; p一点(抱歉)但出于好奇:这是一门课程吗(最近围绕这个问题/数据有很多问题在这里浮动;)-你可以说这门课程是在哪所大学进行的吗?@Carsten肯定是xD这是Peter Symond的学院;p
template.hs:14:27: error:
    • Couldn't match type ‘(Name, Coordinates, TotalPop)’
                     with ‘[([Char], (a0, a1), [a2])]’
      Expected type: [([Char], (a0, a1), [a2])]
        Actual type: Place
    • In the first argument of ‘showPlace’, namely ‘p’
      In the first argument of ‘(++)’, namely ‘showPlace p’
      In the expression: showPlace p ++ "\n"
   |
14 | showPlaces ps = [showPlace p ++ "\n" | p <- ps] where
   |                           ^

template.hs:14:32: error:
    • Couldn't match type ‘Char’ with ‘[Char]’
      Expected type: [[Char]]
        Actual type: [Char]
    • In the second argument of ‘(++)’, namely ‘"\n"’
      In the expression: showPlace p ++ "\n"
      In the expression: [showPlace p ++ "\n" | p <- ps]
   |
14 | showPlaces ps = [showPlace p ++ "\n" | p <- ps] where
   |
import Data.List (intercalate)

showPlaces :: [Place] -> String
showPlaces ps = intercalate "\n" [showData d | d <- ps]
  where
    showData (w, (x, y), z) = w ++ ", (" ++ show x ++ ", " ++ show y ++ "), [" ++ unwords (map show z) ++ "]"