• F#测试记录代码.


    1.动态得到类型.

    #light
    open System.Threading
    open System
    
    type Address = { Name : string;Zip : int}
    let getType (x : obj) =
        match x with
        | :? string -> "x is a string"
        | :? int -> "x is a int"
        | :? System.Exception -> "x is an exception"
        | :? Address -> "x is a Address"
        | :? _ -> "invalid type"   
    
    getType {Name = "2edd" ;Zip = 3} |> Console.WriteLine
    Console.ReadKey true

    2.http://www.cnblogs.com/1-2-3/archive/2010/03/02/grasp-algorithm1.html插入排序算法改个F#版.

    let InsertionSort (s:int[]) =
        for index = 0 to s.Length - 2 do
             let b = s.[index + 1] in
             let j = ref index
             while !j>=0 && s.[!j] > b do
                s.[!j + 1] <- s.[!j]
                j := !j - 1
             s.[!j + 1] <- b
        s  
        
    let cc = InsertionSort [| 4;2;5;10;7 |] 

    其中for .. to ..to 相当于>=.操作符+和数字之间空格不要忘记.

    3.得到相关类型的所有方法.

    4.测试下.

  • 相关阅读:
    shader变体
    正向渲染
    LWPR
    blend
    slua
    unity
    jsBridge
    浏览器
    数据运营系统
    广告
  • 原文地址:https://www.cnblogs.com/zhouxin/p/1673511.html
Copyright © 2020-2023  润新知