Hello Haskellers,<br><br> I isolated to a not so small piece:<br><br>> {-# OPTIONS -fglasgow-exts #-}<br>> {-# LANGUAGE UndecidableInstances #-}<br><br><br>> import Control.Monad.Identity<br>> import Control.Monad.Reader<br>
> import Control.Monad.State<br>> import qualified Data.List as L<br>> import qualified Data.Map as M<br>> import Data.Array<br><br>import IOExts<br><br><br>The type of a regular expression.<br><br>> data Re t<br>
> = ReOr [Re t]<br>> | ReCat [Re t]<br>> | ReStar (Re t)<br>> | RePlus (Re t)<br>> | ReOpt (Re t)<br>> | ReTerm [t]<br>> deriving (Show)<br><br><br>The internal type of a regular expression.<br>
<br>> type SimplRe t = Int<br>> data SimplRe' t<br>> = SReOr (SimplRe t) (SimplRe t)<br>> | SReCat (SimplRe t) (SimplRe t)<br>> | SReStar (SimplRe t)<br>> | SReLambda<br>> | SReNullSet<br>
> | SReTerm t<br>> deriving (Eq, Ord, Show)<br><br><br>The regular expression builder monad.<br><br>> data (Ord t) => ReRead t<br>> = ReRead {<br>> rerNullSet :: SimplRe t,<br>> rerLambda :: SimplRe t<br>
> }<br><br>> data (Ord t) => ReState t<br>> = ReState {<br>> resFwdMap :: M.Map (SimplRe t) (ReInfo t),<br>> resBwdMap :: M.Map (SimplRe' t) (SimplRe t),<br>> resNext :: Int,<br>
> resQueue :: ([SimplRe t], [SimplRe t]),<br>> resStatesDone :: [SimplRe t]<br>> }<br><br>> type ReM m t a = StateT (ReState t) (ReaderT (ReRead t) m) a<br><br>TEMP WNH<br>Dfa construction<br>
<br>> data ReDfaState t<br>> = ReDfaState {<br>> dfaFinal :: Bool,<br>> dfaTrans :: [(t, SimplRe t)]<br>> }<br>> deriving (Show)<br><br>TEMP WNH<br>The ReInfo type<br><br>> data ReInfo t<br>
> = ReInfo {<br>> reiSRE :: SimplRe' t,<br>> reiNullable :: Bool,<br>> reiDfa :: Maybe (ReDfaState t)<br>> }<br>> deriving (Show)<br><br>TEMP WNH<br>
<br><br>> class (Monad m, Ord t) => ReVars m t where { }<br>> instance (Monad m, Ord t) => ReVars m t where { }<br><br>TEMP WNH<br><br>> remLookupFwd :: (ReVars m t) => SimplRe t -> ReM m t (ReInfo t)<br>
> remLookupFwd re<br>> = do fwd <- gets resFwdMap<br>> -- let { Just reinfo = M.lookup fwd re } -- PROBLEM<br>> reinfo <- M.lookup fwd re -- PROBLEM<br>
> return reinfo<br><br><br>When I "compile" with ghci I get:<br><br><br>Dfa_exp.lhs:91:32:<br> Couldn't match expected type `M.Map<br> (M.Map (SimplRe t) (ReInfo t)) t1'<br>
against inferred type `SimplRe t2'<br> In the second argument of `M.lookup', namely `re'<br> In a 'do' expression: reinfo <- M.lookup fwd re<br> In the expression:<br> do fwd <- gets resFwdMap<br>
reinfo <- M.lookup fwd re<br> return reinfo<br><br>I trimmed the original code down a lot! But still can't why I am getting type check errors!!! Help!<br><br>Kind regards,<br><br>Vasili<br><br>
<br><br><br><br><br>