active-pattern

    4熱度

    3回答

    我想了解活動模式,所以我用FizzBu​​zz玩弄: let (|Fizz|_|) i = if i % 3 = 0 then Some Fizz else None let (|Buzz|_|) i = if i % 5 = 0 then Some Buzz else None let (|FizzBuzz|_|) i = if i % 5 = 0 && i % 3 = 0 then Som

    9熱度

    5回答

    Scala中是否存在允許提取器採用自定義參數的語法?這個例子有點做作。假設我在整數上有一個二叉搜索樹,並且如果它的值可以被某個自定義值整除,我想匹配當前節點。 使用F#活動模式,我可以做到以下幾點: type Tree = | Node of int * Tree * Tree | Empty let (|NodeDivisibleBy|_|) x t = mat

    2熱度

    1回答

    在下面的代碼中,我必須在每次迭代中重複使用活動模式結果三次。即 match tree.Parent, postion with 我發現我可以保存活動模式結果。即 let pos = ((|Root|Nil|Single|First|Inner|Last|Unknown|) (tree.Parent, position)) 我無法弄清楚的是如果活動模式結果可用於匹配語句。即 match po

    0熱度

    1回答

    我從一個Web服務下面的XML,我想轉換爲.NET對象: let xmlString = "<?xml version=\"1.0\"?> <logInResponse> <result>OK</result> <xmlLogIn> <session>11C0ED6F8F7288855FC73C99979A9732.TOGKE6VP9aE8abcdLXaVXg</s

    4熱度

    2回答

    我的類型 type tradeLeg = { id : int ; tradeId : int ; legActivity : LegActivityType ; actedOn : DateTime ; estimates : legComponents ; entryType : ShareOrDollarBased ; c

    8熱度

    4回答

    該有源圖案與F#2.0編譯: let (|Value|_|) value = // 'a -> 'T option match box value with | :? 'T as x -> Some x | _ -> None 但是,在F#3.0,發出錯誤: Active pattern '|Value|_|' has a result type containi

    12熱度

    2回答

    對於內聯函數一個可以創建一個約束,如: let inline implicit arg = (^a : (static member op_Implicit : ^b -> ^a) arg) 需要的參數給定的運營商或成員。有沒有一種方法可以基於類似的東西進行匹配? 我想創建一個活躍的格局,其中則傳遞給內聯函數如上述的約束相匹配的方法,任何參數觸發功能和一切爲一些錯誤管理的一部分結束。

    2熱度

    2回答

    升級到VS 2012 RTM後,this question中的活動模式無法編譯。它提供了一種方法來進行類型測試並在單個模式中匹配文字。例如: let (|Value|_|) value = match box value with | :? 'T as x -> Some x | _ -> None let getValue (name: string) (r:

    2熱度

    1回答

    我定義如下活動模式「表達」: let (|Expression|_|) expression _ = Some(expression) 現在我想以這種方式來使用它: match() with | Expression((totalWidth - wLeft - wRight)/(float model.Columns.Count - 0.5)) cw when cw <= wLef

    7熱度

    2回答

    我有一個Dictionary在我最初迭代正是如此: myDictionary |> Seq.iter (fun kvp -> doSomething kvp.Key kvp.Value) 後來,我發現,我可以利用KeyValue活躍格局,而做到這一點: myDictionary |> Seq.iter (fun (KeyValue (k, v)) -> doSomething k v) 知道了積極