Remove subsome type signature. You are redeclaring type variables which obviously cannot match those of legSome.<br>This cannot work without scoped type variables (and ad-hoc foralls to bring them to scope, of course).<br>

<br><div class="gmail_quote">2012/1/3 Yucheng Zhang <span dir="ltr">&lt;<a href="mailto:yczhang89@gmail.com" target="_blank">yczhang89@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">As I investigated the code more carefully, I found that the type unification<br>
failure may not be related to the suspected class constraint on data<br>
constructor.<br>
<br>
I have made minor changes to the original code to remove the Ord constraint,<br>
including introducing a FakedMap with no requirement on Ord. The type<br>
unification<br>
failure continues:<br>
<br>
&gt;    Couldn&#39;t match type `nt1&#39; with `nt&#39;<br>
&gt;      `nt1&#39; is a rigid type variable bound by<br>
&gt;            the type signature for<br>
&gt;              subsome :: [RRule nt1 t1 s1] -&gt; Either String ([t1], s1)<br>
&gt;            at xx.hs:34:19<br>
&gt;      `nt&#39; is a rigid type variable bound by<br>
&gt;           the type signature for<br>
&gt;             legSome :: LegGram nt t s -&gt; nt -&gt; Either String ([t], s)<br>
&gt;           at xx.hs:29:1<br>
&gt;    Expected type: [Symbols nt1 t1]<br>
&gt;      Actual type: [Symbols nt t]<br>
&gt;    In the first argument of `makeWord&#39;, namely `r&#39;<br>
&gt;    In the expression: makeWord r<br>
<br>
The complete changed code follows:<br>
<div><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>
<br>
<br>
<br>
</div>data FakedMap a b = FakedMap<br>
<br>
delete :: k -&gt; FakedMap k a -&gt; FakedMap k a<br>
delete a b = b<br>
<br>
lookup :: k -&gt; FakedMap k a -&gt; Maybe a<br>
lookup a b = Nothing<br>
<br>
<br>
<br>
data LegGram nt t s = LegGram (FakedMap nt [RRule nt t s])<br>
<br>
legSome :: LegGram nt t s -&gt; nt -&gt; Either String ([t], s)<br>
legSome (LegGram g) ntV =<br>
  case Main.lookup ntV g of<br>
<div>    Nothing -&gt; Left &quot;No word accepted!&quot;<br>
</div>    Just l -&gt; let sg = legSome (LegGram (Main.delete ntV g))<br>
<div>                  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>
</div><div><div>_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org" target="_blank">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>
</div></div></blockquote></div><br>