【发布时间】:2017-06-29 03:23:19
【问题描述】:
wrap [1,2,3] should output [[1],[2],[3]]
wrap [[1],[2],[3]] should output [ [[1]], [[2]], [[3]] ]
我的实现是:
wrap [] = []
wrap (x:xs) = [x] : [wrap xs]
并且haskell输出错误:Occurs check: cannotconstruct the infinite type: t ~ [t]
预期类型:[t] -> [t] 实际类型:[t] -> [[t]]
【问题讨论】:
-
wrap (x:xs) = [x] : wrap xs? -
^,但也只是
wrap = map pure。 -
@zerkms,导致无法将类型“a”与“[a]”匹配错误
-
@anru 它完全适合我
¯\_(ツ)_/¯ -
@zerkms,我的错,我输入了 wrap :: [a] -> [a]
标签: haskell