-- base
mread (PIdentifier name) = do
  st <- get
  if name `elem` checked st
    then return [name]
    else do
    d <- findDecl name

    sub <- case d of
      Just expr -> do
        put st { checked = name : checked st }
        mread expr
      Nothing -> return []

    return $ name : sub

  -- look in scope, then decls, mread recursively
mread (PIdentifier name) = do
  st <- get
  if name `elem` checked st
    then return [name]
    else do
    d <- findDecl name

    sub <- case d of
      Just expr -> do
        put st { checked = name : checked st }
        mread expr
      Nothing -> return []

    return $ name : sub

  -- look in scope, then decls, mread recursively
mread (PIdentifier name) = do
  st <- get
  if name `elem` checked st
    then return [name]
    else do
    d <- findDecl name

    sub <- case d of
      Just expr -> do
        put st { checked = name : checked st }
        mread expr
      Nothing -> return []

    return $ name : sub

  -- look in scope, then decls, mread recursively