Perhaps you should give us the error the compiler give you.<br><br>Plus:<br><span style="font-family:courier new,monospace">data LegGram nt t s = Ord nt =&gt; LegGram (M.Map nt [RRule nt t s])</span><br>will become invalid. Currently, such class constraints are ignored.<br>

<br>
You should remove the &#39;Ord nt&#39; constraint and add it to you legSome function. (Maybe that&#39;s a track to solve your problem...)<br><br><br>You have also another solution: make your LegGram type available <b>for all</b> Ord nt (with GADTs or ExistentialQuantification), thus making you unable to know which type &#39;nt&#39; exactly is:<br>

<br><span style="font-family:courier new,monospace">data LegGram t s = forall nt. Ord nt =&gt; LegGram (M.Map nt [RRule nt t s])</span><br>or<br><span style="font-family:courier new,monospace">data LegGram t s where</span><br style="font-family:courier new,monospace">

<span style="font-family:courier new,monospace">    LegGram :: Ord nt =&gt; M.Map nt [RRule nt t s] -&gt; LegGram t s</span><br>should be both valid. I tend to prefer the latter (the use of a GADT), as it makes you declare and handle your type constructor just like any function.<br>

But I don&#39;t know if it fits you requirements.<br><br><br><div class="gmail_quote">2012/1/3 AUGER Cédric <span dir="ltr">&lt;<a href="mailto:sedrikov@gmail.com">sedrikov@gmail.com</a>&gt;</span><br><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">

<br>
Hi all, I am an Haskell newbie; can someone explain me why there is<br>
no reported error in @legSome@ but there is one in @legSomeb@<br>
<br>
(I used leksah as an IDE, and my compiler is:<br>
$ ghc -v<br>
Glasgow Haskell Compiler, Version 7.2.1, stage 2 booted by GHC version<br>
6.12.3 )<br>
<br>
What I do not understand is that the only difference was a typing<br>
anotation to help the type inference, but I believed that this<br>
annotation was already given by the signature I give, so I am quite<br>
lost.<br>
<br>
Thanks in advance!<br>
<br>
======================================================================<br>
{-# OPTIONS_GHC -XScopedTypeVariables #-}<br>
-- why isn&#39;t this option always enabled...<br>
<br>
{-# OPTIONS_GHC -XGADTs #-}<br>
<br>
import Data.Word<br>
import qualified Data.Map as M<br>
import qualified Data.Set as S<br>
<br>
data Symbols nt t = NT nt -- ^ non terminal<br>
                  | T t  -- ^ terminal<br>
 deriving (Eq, Ord)<br>
<br>
type Sem s = [s]-&gt;s<br>
<br>
data Rule nt t s = Rule { refined :: nt<br>
                        , expression :: [Symbols nt t]<br>
                        , emit :: Sem s<br>
                        }<br>
<br>
type RRule nt t s = ([Symbols nt t], Sem s)<br>
data LegGram nt t s = Ord nt =&gt; LegGram (M.Map nt [RRule nt t s])<br>
<br>
legSome :: LegGram nt t s -&gt; nt -&gt; Either String ([t], s)<br>
--         ^^^^^^^^^^^^^^<br>
--            isn&#39;t this redundant?<br>
--                    vvvvvvvvvvvvvv<br>
legSome ((LegGram g)::LegGram nt t s) ntV =<br>
   case M.lookup ntV g of<br>
     Nothing -&gt; Left &quot;No word accepted!&quot;<br>
     Just l -&gt; let sg = legSome (LegGram (M.delete ntV g))<br>
                   subsome :: [RRule nt t s] -&gt; Either String ([t], s)<br>
                   subsome [] = Left &quot;No word accepted!&quot;<br>
                   subsome ((r,sem):l) =<br>
                     let makeWord [] = Right ([],[])<br>
                         makeWord ((NT nnt):ll) =<br>
                           do (m, ss) &lt;- sg nnt<br>
                              (mm, sss) &lt;- makeWord ll<br>
                              return (m++mm, ss:sss)<br>
                         makeWord ((T tt):ll) =<br>
                           do (mm, sss) &lt;- makeWord ll<br>
                              return (tt:mm, sss)<br>
                      in<br>
                    case makeWord r of<br>
                      Right (ll, mm) -&gt; Right (ll, sem mm)<br>
                      Left err -&gt; subsome l<br>
               in subsome l<br>
<br>
legSomeb :: LegGram nt t s -&gt; nt -&gt; Either String ([t], s)<br>
-- but without it I have an error reported<br>
legSomeb (LegGram g) ntV =<br>
   case M.lookup ntV g of<br>
     Nothing -&gt; Left &quot;No word accepted!&quot;<br>
     Just l -&gt; let sg = legSomeb (LegGram (M.delete ntV g))<br>
                   subsome :: [RRule nt t s] -&gt; Either String ([t], s)<br>
                   subsome [] = Left &quot;No word accepted!&quot;<br>
                   subsome ((r,sem):l) =<br>
                     let makeWord [] = Right ([],[])<br>
                         makeWord ((NT nnt):ll) =<br>
                           do (m, ss) &lt;- sg nnt<br>
                              (mm, sss) &lt;- makeWord ll<br>
                              return (m++mm, ss:sss)<br>
                         makeWord ((T tt):ll) =<br>
                           do (mm, sss) &lt;- makeWord ll<br>
                              return (tt:mm, sss)<br>
                      in<br>
                    case makeWord r of<br>
                      Right (ll, mm) -&gt; Right (ll, sem mm)<br>
                      Left err -&gt; subsome l<br>
               in subsome l<br>
<br>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
</blockquote></div><br>