数据声明中的特殊字符

问题描述 投票:0回答:1

从下面的文章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

我将如何在数据声明中使用非字母字符?是否可以使其成为中缀运算符?

haskell
1个回答
0
投票

非中缀构造函数必须以大写字母开头。中缀构造函数必须以:开头。

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
© www.soinside.com 2019 - 2024. All rights reserved.