Saturday, 31 August 2013

Why is List.reduce necessary in this newbie example?

Why is List.reduce necessary in this newbie example?

pPlaying around with F#, I am confused with the following behavior. When
codeList.reduce (gt;gt;)/code is commented out, there is the error/p
precodedefaultLabel |gt; showRainbow ----------------^^^^^^^^^^^ This
expression was expected to have type CoolLabel -gt; 'a but here has type
(CoolLabel -gt; CoolLabel) list /code/pre pin this example boiled down
from a
href=http://fsharpforfunandprofit.com/posts/conciseness-functions-as-building-blocks/
rel=nofollowhttp://fsharpforfunandprofit.com/posts/conciseness-functions-as-building-blocks//a

:/p precode// 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
|gt; List.map setLabel |gt; List.reduce (gt;gt;) // test the showRainbow
function defaultLabel |gt; showRainbow /code/pre pWhen codeList.reduce
(gt;gt;)/code is removed, I would think that showRainbow should return a
list of CoolLabel, and the compiler would be cool with everything. I get
that List.reduce () would return the last CoolLabel from the list.
Thanks./p

No comments:

Post a Comment