从下面的文章Inductive Graphs and Functional Graph Algorithms,数据定义如下
type Node = Int
type Adj b = [(b, Node)]
type Context a b = (Adj b, Node, a, Adj b)
data Graph a b = Empty | Context a b & Graph a b
其中&
是中缀运算符。
我尝试如下复制它
data Graph a b = Empty | (&) (Context a b) (Graph a b) deriving Show
但是我似乎无法打印出来
*Main> (&) ([], 3, 'c',[]) Empty
<interactive>:124:1: error:
Variable not in scope:
(&) :: ([t0], Integer, Char, [t1]) -> Graph a0 b0 -> t
我将如何在数据声明中使用非字母字符?是否可以使其成为中缀运算符?
非中缀构造函数必须以大写字母开头。中缀构造函数必须以:
开头。
data Graph a b = Empty | (:&) (Context a b) (Graph a b) deriving Show
或
data Graph a b = Empty | Context a b :& Graph a b deriving Show