{- P A R T 2 : Implementation of a parser for Łukasiewicz expressions
--TODO Define the type LExpTree, using the constructors L, V, N, Q, S, K, A, O, E, I
L for Lukasiewicz literals (i.e. C, I or U)
V for Variables (string)
N for a node representing the prefix neg
Q for a node representing the prefix pos
S for a node representing the prefix cer
K for a node representing the prefix unk
A for a node representing the infix And
O for a node representing the infix Or
E for a node representing the infix Equivalence
M for a node representing the infix Implication
It will be convenient to have the new type derive from the classes Show and Eq
-}
data LExpTree a = L a
| V [Char]
| N (LExpTree a)
| Q (LExpTree a)
| S (LExpTree a)
| K (LExpTree a)
| A (LExpTree a) (LExpTree a)
| O (LExpTree a) (LExpTree a)
| E (LExpTree a) (LExpTree a)
| M (LExpTree a) (LExpTree a)
deriving (Show, Eq)
Это мой проект Haskell. Я пробовал это в течение 4 дней. Я просто хочу проверить, верны ли мои данные LExpTree
?Haskell при создании новых данных
Я не думаю, хотя ..
После этого я должен создать серию анализаторов в грамматике
Это 3 из них.
{-
lukExp :: lukOpd ('<->' lukExp | '-->' lukExp| e)
lukVar :: lowercase (Alphanumeric)*
lukLit :: C | I | U
-}
lukExp :: Parser LExpTree
lukExp = do o <- lukOpd
(do { symbol "<->";
e <- lukExp;
return (E (o <-> e)); }
+++ do { symbol "-->";
e <- lukExp;
return (E (o --> e)); }
+++ return (E o))
lukVar :: Parser LExpTree
lukVar = ident
lukLit :: Parser LExpTree
lukLit = do { symbol "C";
return (L C); }
+++ do { symbol "I";
return (L I); }
+++ do { symbol "U";
return (L U); }
И я получаю эти ошибки.
proj.hs:131:18:
Expecting one more argument to `LExpTree'
The first argument of `Parser' should have kind `*',
but `LExpTree' has kind `* -> *'
In the type signature for `lukExp': lukExp :: Parser LExpTree
proj.hs:184:18:
Expecting one more argument to `LExpTree'
The first argument of `Parser' should have kind `*',
but `LExpTree' has kind `* -> *'
In the type signature for `lukVar': lukVar :: Parser LExpTree
proj.hs:187:18:
Expecting one more argument to `LExpTree'
The first argument of `Parser' should have kind `*',
but `LExpTree' has kind `* -> *'
In the type signature for `lukLit': lukLit :: Parser LExpTree
Failed, modules loaded: Parser.
Проект заключается в создании Лукасевич выражения C наверняка, U для неопределенной, и я для нельзя.
И у меня уже есть Parser.hs, и он имеет все типы Parser и parse и связанные с ним функции.
Я понимаю, что это школьный проект и должен попробовать все возможное. У меня все еще есть еще две части, и это должно быть легкой частью.
Буду признателен, если кто-то может мне помочь.
Спасибо.
Спасибо за ответ. Я уже объявил этот тип и забыл добавить в вопрос. 'данные Lukasiewicz = C | I | U получение (Eq, Show, Ord) ' И я полностью забыл этот трюк, чтобы использовать GHC для получения типа. :) Спасибо.. – william