CurryInfo: curry-repl-1.2.0 / REPL.Main.makeMainExpMonomorphic

definition:
makeMainExpMonomorphic :: ReplState -> CurryProg -> String
                       -> IO (Maybe (CurryProg, String))
makeMainExpMonomorphic rst prog exp = case prog of
  CurryProg _ _ _ _ _ _ [CFunc _ _ _ qty _] _ -> makeMonoType qty
  _ -> error "REPL.makeMainExpMonomorphic"
 where
  makeMonoType qty@(CQualType _ ty)
    | isFunctionalType ty
    = do writeErrorMsg "expression is of functional type"
         return Nothing
    | isPolyType ty
    = case defaultQualTypeExpr qty of
        CQualType (CContext []) defTy -> do
          when (defTy /= ty) $ writeVerboseInfo rst 2 $
            "Defaulted type of main expression: " ++
            showMonoTypeExpr False defTy
          let (nwexp, whereclause) = breakWhereFreeClause exp
              nwexpR               = addReturn nwexp defTy
              mtype = showMonoTypeExpr True defTy
              mexp  = "(" ++ nwexpR ++ " :: " ++ mtype ++ ") " ++ whereclause
          writeMainExpFile rst (modsOfType defTy) (Just mtype) mexp
          writeVerboseInfo rst 3 $ "New expression: " ++ mexp
          when (isPolyType defTy) $ writeVerboseInfo rst 2 $
            "Type of main expression \"" ++ showMonoTypeExpr False defTy
            ++ "\" made monomorphic by replacing type variables by \"()\""
          getAcyOfMainExpMod rst >>=
            maybe (return Nothing)
                  (\p -> return $ Just (p,mexp))
        _ -> do writeErrorMsg $
                  "cannot handle overloaded top-level expression of type: " ++
                  showMonoQualTypeExpr False qty
                return Nothing
    | otherwise
    = if newexp == exp
        then return $ Just (prog,exp)
        else do writeSimpleMainExpFile rst newexp
                getAcyOfMainExpMod rst >>=
                  maybe (return Nothing)
                        (\p -> return $ Just (p,newexp))
   where
    newexp = let (nwexp, whereclause) = breakWhereFreeClause exp
                 nwexpR               = addReturn nwexp ty
             in nwexpR ++ whereclause

    -- raise ND-in-IO Errors
    addReturn e te = if isIOType te
                       then '(' : e ++ ") Prelude.>>= Prelude.return"
                       else e
demand:
argument 2
deterministic:
deterministic operation
documentation:
--- If the main expression is polymorphic, make it monomorphic by adding
--- a type declaration where type variables are replaced by type `()`.
--- Before, type variables with a numeric constraint like `Num`/`Integral` or
--- `Fractional`/`Floating` are defaulted to the types `Int` or `Float`,
--- respectively. The type of the main expression is only allowed to contain
--- numeric constraints.
--- If the main exp has type `IO t` where t is monomorphic and not a function,
--- t /= (), and `withShow` is `True`, then `>>= print` is added
--- to the expression to print the computed value.
--- Otherwise (if the main exp has type `IO t`), `>>= return` is added
--- in order to support raising non-determinism errors during the
--- monadic bind operation.
--- The arguments are the AbstractCurry program of the main expression
--- and the main expression as a string.
--- The result is Nothing (if some error occurred) or the transformed
--- AbstractCurry program and expression.
failfree:
<FAILING>
indeterministic:
referentially transparent operation
infix:
no fixity defined
iotype:
{(_,{CurryProg},_) |-> _}
name:
makeMainExpMonomorphic
precedence:
no precedence defined
result-values:
_
signature:
REPL.State.ReplState -> AbstractCurry.Types.CurryProg -> String
-> Prelude.IO (Prelude.Maybe (AbstractCurry.Types.CurryProg, String))
solution-complete:
operation might suspend on free variables
terminating:
possibly non-terminating
totally-defined:
possibly non-reducible on same data term