F# をいじってみると、次の動作に混乱しています。List.reduce (>>)
コメントアウトするとエラーになる
defaultLabel |> showRainbow
----------------^^^^^^^^^^^
This expression was expected to have type
CoolLabel -> 'a
but here has type
(CoolLabel -> CoolLabel) list
この例では、 http://fsharpforfunandprofit.com/posts/conciseness-functions-as-building-blocks/から煮詰めました:
// create an underlying type
type CoolLabel = {
label : string;
}
let defaultLabel =
{label="";}
let setLabel msg label =
{label with CoolLabel.label = msg}
let rainbow =
["red";"orange";"yellow";"green";"blue";"indigo";"violet"]
let showRainbow =
rainbow
|> List.map setLabel
|> List.reduce (>>)
// test the showRainbow function
defaultLabel |> showRainbow
が削除された場合List.reduce (>>)
、showRainbow は CoolLabel のリストを返す必要があり、コンパイラはすべてにおいて優れていると思います。
編集 -> (以下の回答で私の理解が変わったので、この文は無視してください。): 「余談ですが、List.reduce (>>) はリストから最後の CoolLabel を返すことがわかりました。」
ありがとう。