zoukankan      html  css  js  c++  java
  • 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.测试下.

  • 相关阅读:
    2-5
    2-4 及 1、2两章 学习心得 和问题
    2-3
    4-8
    4-6
    4-5
    4-4
    4-3
    4-2
    4-1
  • 原文地址:https://www.cnblogs.com/zhouxin/p/1673511.html
Copyright © 2011-2022 走看看