tcr / corollary

Cross-compiler from Haskell to Rust, plus parser-haskell.
73 stars 5 forks source link

Monadic code #16

Open pshc opened 7 years ago

pshc commented 7 years ago

The elephant in the room.

-- | lookup an object, function or enumerator
lookupObject :: (MonadCError m, MonadSymtab m) => Ident -> m (Maybe IdentDecl)
lookupObject ident = do
    old_decl <- liftM (lookupIdent ident) getDefTable
    mapMaybeM old_decl $ \obj ->
        case obj of
        Right objdef -> addRef ident objdef >> return objdef
        Left _tydef  -> astError (nodeInfo ident) (mismatchErr "lookupObject" "an object" "a typeDef")

Right now I'm going to assume we're going to special-case every monad in the codebase so we can get some somewhat reasonable output...?

pshc commented 7 years ago

Maybe we can take a page out of futures's book and actually construct monadic values, 🤷

pshc commented 7 years ago

Suggestion from IRC: https://github.com/TeXitoi/rust-mdo