我需要有关以下错误的帮助。基本上对于给定的项目列表,我想创建一个函数来检查项目是否在该列表中。为了做到这一点,我将列表变成一个集合,然后围绕该集合创建一个闭包。
toAccept :: Ord a => [a] -> (a -> Bool)
toAccept xs =
let xset = Set.fromList xs in
let
-- accept:: Ord a => a -> Bool
accept x = Set.member xset x in
accept
我得到的是
Could not deduce (a ~ Set.Set (Set.Set a))
from the context (Ord a)
bound by the type signature for
toAccept :: Ord a => [a] -> a -> Bool
at Tokens.hs:6:13-39
`a' is a rigid type variable bound by
the type signature for toAccept :: Ord a => [a] -> a -> Bool
at Tokens.hs:6:13
Expected type: a -> Bool
Actual type: Set.Set (Set.Set a) -> Bool
In the expression: accept
In the expression: let accept x = Set.member xset x in accept
In the expression:
let xset = Set.fromList xs in
let accept x = Set.member xset x in accept
我究竟做错了什么?