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"><<a href="mailto:yczhang89@gmail.com" target="_blank">yczhang89@gmail.com</a>></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>
> Couldn't match type `nt1' with `nt'<br>
> `nt1' is a rigid type variable bound by<br>
> the type signature for<br>
> subsome :: [RRule nt1 t1 s1] -> Either String ([t1], s1)<br>
> at xx.hs:34:19<br>
> `nt' is a rigid type variable bound by<br>
> the type signature for<br>
> legSome :: LegGram nt t s -> nt -> Either String ([t], s)<br>
> at xx.hs:29:1<br>
> Expected type: [Symbols nt1 t1]<br>
> Actual type: [Symbols nt t]<br>
> In the first argument of `makeWord', namely `r'<br>
> 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]->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 -> FakedMap k a -> FakedMap k a<br>
delete a b = b<br>
<br>
lookup :: k -> FakedMap k a -> 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 -> nt -> Either String ([t], s)<br>
legSome (LegGram g) ntV =<br>
case Main.lookup ntV g of<br>
<div> Nothing -> Left "No word accepted!"<br>
</div> Just l -> let sg = legSome (LegGram (Main.delete ntV g))<br>
<div> subsome :: [RRule nt t s] -> Either String ([t], s)<br>
subsome [] = Left "No word accepted!"<br>
subsome ((r,sem):l) =<br>
let makeWord [] = Right ([],[])<br>
makeWord ((NT nnt):ll) =<br>
do (m, ss) <- sg nnt<br>
(mm, sss) <- makeWord ll<br>
return (m++mm, ss:sss)<br>
makeWord ((T tt):ll) =<br>
do (mm, sss) <- makeWord ll<br>
return (tt:mm, sss)<br>
in<br>
case makeWord r of<br>
Right (ll, mm) -> Right (ll, sem mm)<br>
Left err -> 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>