zoukankan      html  css  js  c++  java
  • (F#) How to declare variable and function.

    It was really awful that my google browser crashed when I clicking a link by opening in other tab.

    I have to re-write all the words.

    And now, I use Windows Live Writer, hope no crash any more, but who can guarantee?

    Just at the moment after I downloaded a plug-in of windows live write, and when inserting code, Windows Live Writer even crashed.

    OK, don't want to complain more, let’s begin.

    First, please take a look at a simple block of code.

    // Learn more about F# at http://fsharp.net

    let x = 10; // Declaring a variable.
    x = 11; // Reassigned a new value to x.


    let y = 13;
    let z = x + y; // Declared z = x + y.

    let add x y = x + y;

    printf
    "x + y, %i" (add x y);

    Now you have some questions. What's "let" keyword? Why you reassign a value to x? Where is the declaration of function? What's the output?

    Don't worry, below is my answer.

    1. "let" is a very famous keyword which can help declare variable and function.

    2. Reassigned a value, because there will be a warning. In fact, in F#, most of the value cannot be changed once it been assigned, and from the compiler side, it will treat this code as static property.

    3. The declaration of function is "let add x y = x + y". "add" is the name of the function, x and y are the parameters. Return value? Aha, in F# the return value will always be the last code to be executed.

    4. What's the output? As you learned from my No.2 answer, the output is "x + y, 23". Note, not 24.

    Hope this helpful for the beginners. I also a beginner too. ^_^

    (ps: don't laugh at beginner, who won't start from a beginner?)

  • 相关阅读:
    python模块之xlrd,xlwt,读写execl(xls,xlsx)
    Gulp的常见用法
    Linux常用操作及命令大全
    解决谷歌云 ssh 登录权限被拒的问题 google cloud (publickey,gssapi-keyex,gssapi-with-mic)
    创建web服务器
    网站与服务器的基本知识
    flex布局与移动页面适应
    史上最全的maven的pom.xml文件详解
    linux maven安装
    在 Linux 下搭建 Git 服务器(yum安装)
  • 原文地址:https://www.cnblogs.com/lucasluo/p/1882333.html
Copyright © 2011-2022 走看看