我已经在Haskell中将一个集合实现为二叉树,如下所示:
data Set a = Node | Tree a (Set a) (Set a)
我正在尝试定义一个函数,以找到两个集合的笛卡尔积,如下所示:
cartesian :: Set a -> Set b -> Set (a, b)
cartesian as bs = fromList [(a,b) | a <- (toList as), b <- (toList bs)]
我似乎无法看出这段代码的错误,希望能得到帮助和修复。
错误消息是:
error:
• No instance for (Ord a) arising from a use of ‘fromList’
Possible fix:
add (Ord a) to the context of
the type signature for:
cartesian :: forall a b. Set a -> Set b -> Set (a, b)
• In the expression:
fromList [(a, b) | a <- (toList as), b <- (toList bs)]
In an equation for ‘cartesian’:
cartesian as bs
= fromList [(a, b) | a <- (toList as), b <- (toList bs)]