2
votes

How come that I can do:

let printTeams x : unit = 
    let rnd = new Random()
    Seq.toList x |> List.sortBy (fun x -> rnd.Next()) |> printTeams'

but not:

let printTeams x : unit = 
    let rnd = new Random()
    printTeamsRec'  <| Seq.toList x <| List.sortBy(fun x -> rnd.Next())

I'm just getting an error on the last one, which says:

Type mismatch. Expecting a string list -> 'a -> 'b but given a
string list -> unit The type ''a -> 'b' does not match the type 'unit'

The error occures on the third line at printTeamsRec'

Any help would be appreciate.

1
Is it valid in F# to use a projection which returns different values for the same element if called more than once? - Chris Pitman

1 Answers

6
votes

Two things: the translation of the forward pipe to backwards pipe is incorrect, and precedence is different.

let printTeams x : unit = 
    let rnd = new Random()
    printTeamsRec' <| (List.sortBy(fun x -> rnd.Next()) <| Seq.toList x)