Yes, but you need a discrete value to match on. You are matching on a function, which won't work.

So, you need to apply your function (f:seq->int) to a sequence, to get a discrete value, and then do the match.

If we modify your function to take a sequence as an additional parameter....

let anotherFunction (f:seq<'a>->int) aSeq =

match f aSeq with

| 1 -> printfn "1"

| 2 -> printfn "2"

| n -> printfn "%i" n

(Note that type inference will assign Seq<'a> to aSeq)

Then you call it...

eg.

> anotherFunction Seq.hd (seq {1..10});;

1

nb. Seq.hd is an F# library function. You put your user defined function there.

ie.
> anotherFunction <MyFunction> <mySeq>

By on 6/11/2009 9:58 PM ()

Yes, let-bound functions and lambdas are function "values", so there's nothing special to do:

1
2
3
4
5
6
7
8
9
10
 

let CallFOnThreeCopiesOfX f x =

    let threeCopiesOfX = [x; x; x]

    f threeCopiesOfX

CallFOnThreeCopiesOfX (printfn "%A") 42

Here even the types are inferred (e.g. f is a function 'a list -> b, x is an 'a, whole thing returns a 'b).

By on 6/11/2009 9:47 PM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper