我正在尝试Haskell 99问题,我的第一次尝试就是这个问题.虽然解决方案可能有点不正确,但我只是想知道为什么Haskell会对第一个问题发出警告并输出错误的结果
> let { mylast (x:xs) = mylast xs; mylast [] = 0 ;mylast [x] = x;}
Pattern match(es) are overlapped
> mylast [1,2,3,58,8,6,1,231,10]
> 0
Run Code Online (Sandbox Code Playgroud)
但是下面的代码执行得很好.
> let { mylast [] = 0 ;mylast [x] = x;mylast (x:xs) = mylast xs;}
> mylast [1,2,3,58,8,6,1,231,10]
> 10
Run Code Online (Sandbox Code Playgroud) 我无法记住量化,即我知道它们的意思但是有没有人有一个简单的方法来回忆哪一个代表哪个?
? The question mark indicates there is zero or one of the preceding element.
* The asterisk indicates there is zero or more of the preceding element.
+ The plus sign indicates there is one or more of the preceding element.
Run Code Online (Sandbox Code Playgroud)
我将举例说明我正在寻找的答案.
为区分水平和垂直,取第一个字母H,字母'H'中间的线是单词表示的方向.字母'V'有两条向上的线,这就是这个单词所指的方向.