Created
August 11, 2010 17:28
-
-
Save heedley/519352 to your computer and use it in GitHub Desktop.
Generic Functions in f# notes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // val condPrint : 'a -> ('a -> bool) -> ('a -> string) -> unit | |
| // function that takes three params and returns nothing. | |
| // param1: 'a => a generic generalized (untyped) value | |
| // param2: ('a -> bool) => a function taking 1 param as a generic generalized (untyped) value abd returning a bool | |
| // param3: ('a -> string) => a function taking 1 param as a generic generalized (untyped) value and returning a string | |
| let condPrint value test format = | |
| if (test(value)) then printfn "%s" (format(value)) | |
| // Test the function: | |
| condPrint 10 (fun n -> n > 5) | |
| (fun n -> "Number: " + n.ToString());; | |
| (* | |
| Number: 10 | |
| val it : unit = () | |
| *) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment