【发布时间】:2015-11-17 13:12:07
【问题描述】:
嗨,我有一个数据类型是
data MyIntStr = MyIntStr { intList :: IntList, strList :: StrInt}
type IntList = [[Int]]
type StrList = [[String]]
我想在MyData 的intList 和strList 中添加一些东西。所以我传递了一个空的默认数据,然后尝试将 Ints 添加到Intlist:
putInts :: [Int] -> MyIntStr -> MyIntStr
putInts (h:t) d
|length t /= 0 = putInts t (intList:h)
|otherwise intList:h
这给出了错误任何想法如何做到这一点?
【问题讨论】:
-
1.
data是一个关键字。您不能将其用作变量的名称。 2.intList的类型为MyData -> IntList。 -
@chi 太没用了
-
@NeoStreets 这将是长期的。
-
@NeoStreets chi 的目标差不多,但还是有一些代码:
putInts is d = d { intList = intList d ++ is }。
标签: list haskell types functional-programming