I wrote a program with haskell
but I got errors from ghci
here is the source codes,I construct it, and if I have
p1 :: Prop
p1 = And (Var 'A') (Not (Var 'A'))
It will show A && ~A
so that is the source codes
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 ++ ")"
And I got two main errors from ghci...
Not in scope: data constructor `Char'
Not in scope: data constructor `Prop'
I am a beginner with haskell,thankyou very much.
Value names that start with an uppercase letter are reserved for constructors, like Var
, True
, False
, etc. Variables must start with a lowercase letter.
Additionally, you can't use the same name for two different variables. How would Haskell know which one you meant each time you used them? You can't simply use the definition of a constructor as a pattern in a function; you need to give a separate name to each field.
So, instead of Var Char
, write Var name
; instead of Imply Prop Prop
, write Imply p q
(or Imply prop1 prop2
), and so on.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With