Creating Delegates With Lambda Expressions in F#

Posted by Matt H on Stack Overflow See other posts from Stack Overflow or by Matt H
Published on 2010-05-06T18:25:18Z Indexed on 2010/05/06 18:28 UTC
Read the original article Hit count: 210

Why does...

type IntDelegate = delegate of int -> unit

type ListHelper =
    static member ApplyDelegate (l : int list) (d : IntDelegate) =
        l |> List.iter (fun x -> d.Invoke x)

ListHelper.ApplyDelegate [1..10] (fun x -> printfn "%d" x)

not compile, when:

type IntDelegate = delegate of int -> unit

type ListHelper =
    static member ApplyDelegate (l : int list, d : IntDelegate) =
        l |> List.iter (fun x -> d.Invoke x)

ListHelper.ApplyDelegate ([1..10], (fun x -> printfn "%d" x))

does?

The only difference that is that in the second one, ApplyDelegate takes its parameters as a tuple.

Error 1 This function takes too many arguments, or is used in a context where a function is not expected

© Stack Overflow or respective owner

Related posts about F#

Related posts about functional-programming