如果你想使用rmax
内nmax
,pass
和fail
没有把它当作一个arguement,你需要把它列入的generateUpTo
的where
块。否则,它的字面意思是“不在范围内”。例如:
generateUpTo rmax = check rmax
where
check pass = pAllSorted
check fail = error "insert multiple of 10!"
nmax = rmax `div` 10
pass = rmax `elem` mot
fail = rmax `notElem` mot
如果你想在多个地方使用这些功能,你可以只accect RMAX作为arguement:
nmax rmax = rmax `div` 10
pass rmax = rmax `elem` mot
fail rmax = rmax `notElem` mot
注意 - 它看起来像你也有一些问题,你的定义check
... pass
和fail
值只有check
的争论,而不是你上面定义的函数。
更新
使用n最大(外最,其中块范围的版本),你需要RMAX的值传递给它。像这样:
nmax rmax -- function application in Haskell is accomplished with a space,
-- not parens, as in some other languages.
但是请注意,在nmax
定义名称rmax
不再显著。这些功能都是完全一样的:
nmax rmax = rmax `div` 10
nmax a = a `div` 10
nmax x = x `div` 10
同样,你不需要有一个名为rmax
值来调用它。
nmax rmax
nmax 10 -- this is the same, assuming rmax is 10
nmax foo -- this is the same, assuming foo has your 'rmax' value.
对于一直投票Haskell初学者问题的人来说,如果你能知道,请留下评论,告诉你为什么要这样做。 – Phyx 2012-01-01 16:49:38
我们会外出给他投票的! :)更严重的是,对于那些问我“为我工作”的作业问题的人来说,存在着很多的滥用,也许这是一个错误。 – gatoatigrado 2012-01-01 22:41:13
@Phyx事实上,我尽量不要投新手问题,但也许我可以解释downvoter。这些问题中的大部分都是“过于本地化”的用语,更一般地说,这些用语并不有趣。 – 2012-01-01 23:40:04