Advertisement
Guest User

Untitled

a guest
Aug 21st, 2016
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 0.75 KB | None | 0 0
  1. // this function will call the function passed as "funct" if the temp is in the allowed range. Otherwise it will return "Error"
  2. let validate funct temp =
  3.    match temp with
  4.    | temp when (temp > -217 && temp < 1000) -> funct temp
  5.    | _ -> "Error"
  6.  
  7. // This is a really simple Frozen/Not Frozen function which doesn't check for a valid temp range
  8. let frozen temp =
  9.    match temp with
  10.    | temp when (temp > 0) -> "Not Frozen"
  11.    | _ -> "Frozen"
  12.  
  13. // here, we wrap the simple function with the one which checks for valid ranges
  14. let wrapped = validate frozen
  15.  
  16. [<EntryPoint>]
  17. let main args =
  18.    printfn "-300: %s" (wrapped -300)
  19.    printfn "-200: %s" (wrapped -200)
  20.    printfn "   0: %s" (wrapped 0)
  21.    printfn "unwrapped -300: %s" (frozen -300)
  22.    0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement