unit-type

    1熱度

    1回答

    我發現自己做這個偶然: if some_condition then expr else () 有沒有一種更好的方式來做到這一點?看來應該有一個單線。 (把它全部放入一行不計算在內,我的意思是「在一行中表示我的意圖的東西」)

    6熱度

    3回答

    如何從f#中的表達式返回unit?例如: let readInt = let str = Console.ReadLine() let (succ, num) = Int32.TryParse(str) match succ with | true -> Some(num) | _ -> None match readInt

    2熱度

    2回答

    我在看,我在一個培訓班看到的和無法理解,在下面的函數結束時使用「()」函數: let acclock (start:DateTimeOffset) rate() = let now = DateTime.Now let elapsed = now - start start.AddTicks (elapsed.Ticks * rate) 爲什麼一個函數簽名必須在一

    7熱度

    1回答

    我特意加X本功能 let myMax x y = if x > y then x else y x 我期待x和y參數仍是「一類的結束,但我得到這個簽名: myMax : x:unit -> y:unit -> unit 爲什麼這些推斷有單位類型的參數? 編輯: 謝謝@吉爾斯的答案。考慮這兩個功能: let foo x y = 0 // warning

    1熱度

    1回答

    成員以下工作正常: type T = int type I = abstract member Ok : int abstract member Ok2 : T type C() = interface I with member this.Ok = 1 member this.Ok2 = 1 但是,如果別名是一個函數,而不是一個方法

    2熱度

    1回答

    我正在尋找一種在F#中定義無參數lambda表達式的方法,很像下面的C#示例。 var task =() => { int x = 3; DoSomething(x); } 我嘗試以下 let task = fun _ -> let x = 3 doSomething x 它編譯,但它給了我task : (

    1熱度

    2回答

    我知道如果沒有其他東西被返回,F#函數會返回一個單元,但是這個函數返回一個字符串。有人可以幫我理解爲什麼它會返回一個單位嗎? let rec processList aList str = match aList with | h::t -> let x = Regex.Replace(str, h, h, RegexOptions.IgnoreCase) pr

    10熱度

    4回答

    This memoize function在運行時帶有空參數異常的任何類型爲() -> 'a的函數都會失敗。 let memoize f = let cache = System.Collections.Generic.Dictionary() fun x -> if cache.ContainsKey(x) then cache.[x]

    7熱度

    2回答

    考慮這個接口: type A<'a> = abstract X : 'a 讓我們試着去實現它與int作爲一般的說法: { new A<int> with member this.X = 5 } // all is well 現在,讓我們試着unit一個說法: // Compiler error: The member 'get_X : unit -> unit' does not

    17熱度

    2回答

    Rust具有單元類型,(),這是一種具有單一零大小值的類型。此單位類型的值也使用()指定。 單元類型及其值的目的是什麼?是否像其他語言一樣使用null(或無)?