Skip to content

Instantly share code, notes, and snippets.

@heedley
Created August 11, 2010 17:28
Show Gist options
  • Save heedley/519352 to your computer and use it in GitHub Desktop.
Save heedley/519352 to your computer and use it in GitHub Desktop.
Generic Functions in f# notes
// 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