Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Haskell where子句中的模式匹配不仅匹配模式表达式的LHS部分,而且匹配表达式的RHS部分吗。?_Haskell_Pattern Matching - Fatal编程技术网

Haskell where子句中的模式匹配不仅匹配模式表达式的LHS部分,而且匹配表达式的RHS部分吗。?

Haskell where子句中的模式匹配不仅匹配模式表达式的LHS部分,而且匹配表达式的RHS部分吗。?,haskell,pattern-matching,Haskell,Pattern Matching,我在教程()中看到了这些代码 但我对这里感到困惑 where (f:_) = firstname (l:_) = lastname 当这两种模式完全相同时,它们之间的唯一区别是方程的RHS,一个是firstname,另一个是lastname 那么where子句中的模式匹配不仅匹配模式表达式的LHS部分,而且匹配表达式的RHS部分吗?模式: where (f:_) = firstname 相当于f=headfirstname。特别是,如果firstname是空列表,它

我在教程()中看到了这些代码

但我对这里感到困惑

 where (f:_) = firstname  
       (l:_) = lastname   
当这两种模式完全相同时,它们之间的唯一区别是方程的RHS,一个是firstname,另一个是lastname

那么where子句中的模式匹配不仅匹配模式表达式的LHS部分,而且匹配表达式的RHS部分吗?

模式:

where (f:_) = firstname
相当于
f=headfirstname
。特别是,如果
firstname
是空列表,它将抛出异常

因此where子句中的两种模式相当于:

where f = head firstname
      l = head lastname
函数也可以这样编写:

initials (f:_) (l:_) = [f] ++ ". " ++ [l] ++ "."

这可能会更清楚地表明,除非名字和姓氏都不是空的,
首字母将失败。

它与RHS上的表达式生成的值与LHS上的模式匹配。是的,实际上它是一个赋值表达式,不是函数。
initials (f:_) (l:_) = [f] ++ ". " ++ [l] ++ "."