parseNamedType  = do ty <- identifier
                     if isUpper $ ty !! 0
                       then makeNamedType ty
                       else fail "types must start with an uppercase letter"
    where makeNamedType ty       = do ctx <- getState 
                                      throwsToParser $ makeTyVarOrTyId ty ctx
          makeTyVarOrTyId ty ctx = catchError (makeTyVar ty ctx) 
                                   (\e -> return $ TyId ty)
          makeTyVar       ty ctx = do idx <- indexOf ty ctx
                                      return $ TyVar $ TmVar idx (ctxLength ctx)
parseNamedType  = do ty <- identifier
                     if isUpper $ ty !! 0
                       then makeNamedType ty
                       else fail "types must start with an uppercase letter"
    where makeNamedType ty       = do ctx <- getState 
                                      throwsToParser $ makeTyVarOrTyId ty ctx
          makeTyVarOrTyId ty ctx = catchError (makeTyVar ty ctx) 
                                   (\e -> return $ TyId ty)
          makeTyVar       ty ctx = do idx <- indexOf ty ctx
                                      return $ TyVar $ TmVar idx (ctxLength ctx)
parseNamedType  = do ty <- identifier
                     if isUpper $ ty !! 0
                       then makeNamedType ty
                       else fail "types must start with an uppercase letter"
    where makeNamedType ty       = do ctx <- getState 
                                      throwsToParser $ makeTyVarOrTyId ty ctx
          makeTyVarOrTyId ty ctx = catchError (makeTyVar ty ctx) 
                                   (\e -> return $ TyId ty)
          makeTyVar       ty ctx = do idx <- indexOf ty ctx
                                      return $ TyVar $ TmVar idx (ctxLength ctx)