我写了一个程序haskell
但我从 ghci 收到错误
这是源代码,我构建它,如果我有
p1 :: Prop
p1 = And (Var 'A') (Not (Var 'A'))
它将显示A && ~A
这就是源代码
import Data.List
import Data.Char
data Prop = Const Bool |
Var Char |
Not Prop |
And Prop Prop |
Or Prop Prop |
Imply Prop Prop
deriving Eq
instance Show Prop where
show (Var Char) = show Char
show (Not Prop) = "(~" ++ show Prop ++ ")"
show (And Prop Prop) = "(" ++ show Prop ++ "&&" ++ show Prop ++ ")"
show (Or Prop Prop) = "(" ++ show Prop "||" ++ show Prop ++ ")"
show (Imply Prop Prop) = "(" ++ show Prop "=>" show Prop ++ ")"
我从 ghci 得到了两个主要错误......
Not in scope: data constructor `Char'
Not in scope: data constructor `Prop'
我是 haskell 的初学者,非常感谢。
以大写字母开头的值名称保留用于构造函数, like Var
, True
, False
等。变量必须以小写字母开头。
此外,不能对两个不同的变量使用相同的名称。每次使用它们时,Haskell 如何知道你指的是哪一个?您不能简单地将构造函数的定义用作函数中的模式;您需要为每个字段指定一个单独的名称。
所以,而不是Var Char
, write Var name
;代替Imply Prop Prop
, write Imply p q
(or Imply prop1 prop2
), 等等。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)