如何解决模式匹配期间无法匹配Haskell中的预期类型
我已从以下网址的“实用的Haskell:编程的真实世界指南”中复制了这段代码1:1。 Alejandro Serrano Mena,但由于某些原因,它无法正确输入信息。
module Chapter2.Datatypes2 where
data Person = Person String String Gender
deriving Show
data Gender = Male | Female | Unknown
deriving Show
data Client = GovOrg String
| Company String Integer Person String
| Individual Person Bool
deriving Show
clientName :: Client -> String
clientName client = case client of
GovOrg name -> name
Company name _ _ _ -> name
Individual person ads ->
case person of
Person fNm lNm gender -> fNm ++ " " ++ lNm
编译可以正常进行,但是当我使用(Individual [Person "Jack" "Smith" Male]) False
输入函数时,它会从解释器中收到以下错误:
<interactive>:27:1: error:
* Couldn't match expected type `Bool -> t'
with actual type `[Char]'
* The function `clientName' is applied to two arguments,but its type `Client -> [Char]' has only one
In the expression:
clientName (Individual [Person "Jack" "Smith" Male]) False
In an equation for `it':
it = clientName (Individual [Person "Jack" "Smith" Male]) False
* Relevant bindings include it :: t (bound at <interactive>:27:1)
<interactive>:27:13: error:
* Couldn't match expected type `Client'
with actual type `Bool -> Client'
* Probable cause: `Individual' is applied to too few arguments
In the first argument of `clientName',namely
`(Individual [Person "Jack" "Smith" Male])'
In the expression:
clientName (Individual [Person "Jack" "Smith" Male]) False
In an equation for `it':
it = clientName (Individual [Person "Jack" "Smith" Male]) False
<interactive>:27:24: error:
* Couldn't match expected type `Person' with actual type `[Person]'
* In the first argument of `Individual',namely
`[Person "Jack" "Smith" Male]'
In the first argument of `clientName',namely
`(Individual [Person "Jack" "Smith" Male])'
In the expression:
clientName (Individual [Person "Jack" "Smith" Male]) False
解决方法
for T in range(100):
x = x_list[T]
y = y_list[T]
plt.scatter(x,y,label="T{}".format(T))
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。