[英]Couldn't bind [Char] with actual type (Maybe a)
So I have this: 所以我有这个:
lstDelete :: [Char] -> Lst a -> Lst a
lstDelete k inp@(lstNode key)
| k == key && lstIsEmpty = Map.delete key (Map.fromList inp)
The problem is, k is of type [Char], and key is of type (Maybe a): 问题是,k是[Char]类型,而key是(也许a)类型:
data Lst a = lstNode (Maybe a)
So I'm getting the error saying: 所以我收到错误消息:
Couldn't match expected type ‘[Char]’ with actual type ‘Maybe a’
How can I fix this without changing lstDelete :: [Char] -> Lst a -> Lst a
? 我如何在不更改lstDelete :: [Char] -> Lst a -> Lst a
情况下解决此问题? I also want to keep the Maybe a
since I want it to be able to be empty too. 我也想保留Maybe a
因为我也希望它可以为空。
There is several problem with your code: 您的代码有几个问题:
data Lst a = LstNode (Maybe a)
Your list can contain only one value 您的清单只能包含一个值
lstDelete
doesn't make any sense. lstDelete
没有任何意义。 It accept [Char]
as key and Lst a
as list. 它接受[Char]
作为键,并接受Lst a
作为列表。 There is no way to compare them (there is no nontrivial function that can accept those parameters). 无法比较它们(没有非平凡的函数可以接受这些参数)。 You should either change type to 您应该将类型更改为
lstDelete :: [Char] -> Lst [Char] -> Lst [Char]
or write more generic 或者写更通用的
lstDelete :: Eq a => a -> Lst a -> Lst a
Map.fromList
accepts [(k, v)]
, you can't pass Lst a
to it. Map.fromList
接受[(k, v)]
,您不能将Lst a
传递给它。 lstIsEmpty
is not defined. lstIsEmpty
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.