Advertisement
Guest User

Untitled

a guest
Mar 10th, 2015
286
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Only one line is different (the second one), and one can deal with several kind of parameters, while the other can't :
  2.  
  3. ----------------------- Works :
  4. let string_d =
  5.     let t = 3.1 in
  6.     (fun brick_name brick_verb verb x ->
  7.     Printf.ksprintf (fun s ->
  8.              if verb <= brick_verb
  9.              then Printf.printf "[%s]%s" brick_name s else ()) x)
  10. ;;
  11.  
  12.  
  13. ----------------------- Doesn't works :
  14. let string_d =
  15.     let t = Sys.time () in
  16.     (fun brick_name brick_verb verb x ->
  17.     Printf.ksprintf (fun s ->
  18.              if verb <= brick_verb
  19.              then Printf.printf "[%s]%s" brick_name s else ()) x)
  20. ;;
  21.  
  22.  
  23.  
  24. ----------------------- PROF :
  25.  
  26.  
  27.  
  28. let string_d =
  29.     let t = 3.1 in
  30.     (fun brick_name brick_verb verb x ->
  31.     Printf.ksprintf (fun s ->
  32.              if verb <= brick_verb
  33.              then Printf.printf "[%s]%s" brick_name s else ()) x)
  34. ;;
  35.             Characters 23-24:
  36.       let t = 3.1 in
  37.           ^
  38. Warning 26: unused variable t.
  39. val string_d : string -> 'a -> 'a -> ('b, unit, string, unit) format4 -> 'b =
  40.   <fun>
  41. # string_d "brickname" 5 1 "bonjour %s" "hi";;
  42. [brickname]bonjour hi- : unit = ()
  43. # string_d "brickname" 5 1 "bonjour %d" 4;;
  44. [brickname]bonjour 4- : unit = ()
  45. # let string_d =
  46.     let t = Sys.time () in
  47.     (fun brick_name brick_verb verb x ->
  48.     Printf.ksprintf (fun s ->
  49.              if verb <= brick_verb
  50.              then Printf.printf "[%s]%s" brick_name s else ()) x)
  51. ;;
  52.             Characters 23-24:
  53.       let t = Sys.time () in
  54.           ^
  55. Warning 26: unused variable t.
  56. val string_d :
  57.   string -> '_a -> '_a -> ('_b, unit, string, unit) format4 -> '_b = <fun>
  58. # string_d "brickname" 5 1 "bonjour %s" "hi";;
  59. [brickname]bonjour hi- : unit = ()
  60. # string_d "brickname" 5 1 "bonjour %d" 4;;
  61. Characters 25-37:
  62.   string_d "brickname" 5 1 "bonjour %d" 4;;
  63.                            ^^^^^^^^^^^^
  64. Error: This expression has type
  65.          (string -> unit, string -> unit) CamlinternalFormatBasics.precision
  66.        but an expression was expected of type
  67.          (string -> unit, int -> 'a) CamlinternalFormatBasics.precision
  68.        Type string is not compatible with type int
  69. #
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement