实例显示特定数据



我已经定义了以下类型:

   data Taula = Taula String [[String]]

我创建了以下实例:

instance Show Taula   
   where 
     show  Taula [( n , i , c )]  = show  Taula [( n , i , c )]++ "n" 
     show ( l : ls )  = show l ++  "n"  ++ show ls  

但会生成以下错误:

  Equations for `show' have different numbers of arguments
  lastHaskell.hs:184:18-82
  lastHaskell.hs:185:18-63
  In the instance declaration for `Show Taula'

然后尝试将问题分为以下不同的方法:

  instance Show mostrarTaula where
      show (Taula sep []) = ""
      show (Taula sep (k:lls) ) =  show ([tractar sep k]) ++ "n" 
                                 ++ show (mostrarTaula (Taula sep lls))
--["Hola","Que","fas"] --> "HolakkQuekkfas"
 tractar :: String -> [String] -> String
 tractar sep [] = ""
 tractar sep par = (head par) ++ sep ++ tractar sep (drop 1 par) 
  mostrarTaula :: Taula -> [String] --[[String]] = lls i k=[String]
  mostrarTaula (Taula sep []) = [""]
 mostrarTaula (Taula sep (k:lls) ) =  [tractar sep k] ++ (mostrarTaula(Taula sep lls))

我能做的?我尝试的是打印一个由[(字符串,字符串,字符串)]组成的数据类型?我想以表格形式显示数据。每个元组后用 n。

输出示例:

first element tuple1 Second element tuple1 third element tuple1 first element tuple2 Second element tuple2 third element tuple2 first element tuple3 Second element tuple3 third element tuple3

我不完全理解想要输出是什么,但是也许您可以适应以下内容:

instance Show Taula where
  show (Taula sep []) = ""
  show (Taula sep (k:lls)) = tractar sep k ++ "n" ++ show (Taula sep lls)

最新更新