我已从以下网址的“实用的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
答案 0 :(得分:2)
for T in range(100):
x = x_list[T]
y = y_list[T]
plt.scatter(x, y, label="T{}".format(T))