{- 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)
Ceci est mon projet Haskell. Je l'ai essayé pendant 4 jours. Je veux juste vérifier si mes données LExpTree
sont correctes?Haskell créant de nouvelles données
Je ne pense pas que ..
Après cela, je dois créer une série de parseurs comme la grammaire
Ceci est 3 d'entre eux.
{-
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); }
Et je reçois ces erreurs.
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.
Le projet est de créer des expressions Łukasiewicz C pour certains, U incertain et I pour impossible.
Et j'ai déjà un Parser.hs chargé et il a tous les types Parser et parse et ses fonctions associées. Je comprends que c'est un projet d'école et supposé essayer de mon mieux. J'ai encore 2 parties et c'est supposé être une partie facile.
J'apprécierais que quelqu'un puisse m'aider.
Merci.
Merci pour la réponse. J'ai déclaré ce type avant et j'ai oublié d'ajouter à la question. 'données Lukasiewicz = C | Je | U dérivant (Eq, Show, Ord) ' Et j'ai complètement oublié cette astuce pour utiliser GHC pour obtenir le type. :) Merci beaucoup.. – william