【发布时间】:2021-09-19 22:23:21
【问题描述】:
我不知道如何完成我的代码,需要帮助。
我需要的函数应该能够计算字符串列表中的字符数。
例如:
charLena (createStrLst ["avd", "d4sf"] ["asvd","a2e","bdsh"]) --output is 7 (Total length of the first List)
charLenb (createStrLst ["avd", "d4sf"] ["asvd","a2e","bdsh"]) --output is 11 (Total length of the second List)
这些是我拥有和可以使用的功能:
data StrLst = StrLst [String] [String] deriving (Eq)
StrLst :: [String] -> [String] -> StrLst
createStrLst :: [String] -> [String] -> StrLst
numa :: StrLst -> Int --number of strings in a
numb :: StrLst -> Int --number of strings in b
lena :: StrLst -> Int -> Int --length of (i+1)-th string in a
lenb :: StrLst -> Int -> Int --length of (i+1)-th string in b
createStrLst a b = (StrLst a b)
numa (StrLst a b) = length a
numb (StrLst a b) = length b
lena (StrLst a b) i = length (a!!i)
lenb (StrLst a b) i = length (b!!i)
现在我需要第一个字符串列表charLena 和第二个字符串列表charLenb 的长度。
我也可以使用map 和递归以及haskell 的基本命令(没有其他)
但是如何通过 StrLst 数据类型进行映射??
【问题讨论】:
-
那么你有什么尝试?你被困在哪里了?你不明白什么?我们愿意提供帮助,但这不是一项自行完成的服务。
-
我不知道如何映射
StrLst数据类型,因为这对我来说是新的