سؤال

هل تعرف أن أجمل طريقة لجعل هذا العمل: giveacodicetagpre.

يجب أن يكون هناك طريقة أفضل من إعادة كتابة FST ..

تحديث بعد نصيحة الوسادة، أعدت كتابة التعبئة السابقة "A * 'B إلى بنية واحدة يشبه الرمز الخاص بي الآن giveacodicetagpre.

هل كانت مفيدة؟

المحلول

Why don't you just write it explicitly:

let toTableau2D (a, b, c) =
   let toto = a
   // ...

If you want to refer to seqinit later on, you always can reconstruct the triple or use the named pattern:

let toTableau2D ((a, b, c) as seqinit) =
   let toto = a
   // Do something with seqinit
   // ...

EDIT:

Unless you use reflection, you cannot have fst function for any kind of tuples. In your example, writing some utility functions and reusing them doesn't hurt:

let fst3 (a, _, _) = a
let snd3 (_, b, _) = b
let thd3 (_, _, c) = c

let toTableau2D (seqinit: seq<'a*'b*'c>) =
   let inputd = seqinit |> groupBy2 fst3 snd3
   // ...

If you want to make this work for arbitrary number of tuple elements, consider changing tuples to lists and employing pattern matching on lists.

نصائح أخرى

+1 to what @pad said. Otherwise (if you just simplified what you're trying to do and are stuck with seqinit defined that way) I guess you can always do:

let toTableau2D (seqinit:'a*'b*'c) =
   let toto, _, _ = seqinit          
   //...
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top