相关疑难解决方法(0)

F#函数多次退出

我可以在C++中轻松地做到这一点(注意:我没有测试它的正确性 - 它只是为了说明我正在尝试做什么):

   const int BadParam = -1;
   const int Success = 0;

   int MyFunc(int param)
   {
      if(param < 0)
      {
         return BadParam;
      }

      //normal processing

      return Success;
   }
Run Code Online (Sandbox Code Playgroud)

但我无法弄清楚如何在F#早期退出例行程序.我想要做的是在输入错误时退出该功能,但如果输入正常则继续.我错过了F#的一些基本属性,还是因为我刚刚学习FP而以错误的方式解决问题?是failwith我在这里唯一的选择?

这是我到目前为止所得到的,它编译好了:

   #light

   module test1

       (* Define how many arguments we're expecting *)
       let maxArgs = 2;;
       (* The indices of the various arguments on the command line *)
       type ProgArguments =
           | SearchString = 0
           | FileSpec = 1;;

       (* Various errorlevels which the app can return and …
Run Code Online (Sandbox Code Playgroud)

f# idioms structure

12
推荐指数
3
解决办法
4141
查看次数

标签 统计

f# ×1

idioms ×1

structure ×1