Saturday, December 17, 2022

[FIXED] What is the meaning of parameters starting with tilde ~ in functions?

Issue

What is the meaning of parameters starting with tilde ~ in functions, like in the this example:

let draw_line ~img ~color ~p0:(x0,y0) ~p1:(x1,y1) = ...

Solution

They are named parameters where the label is the same as the formal parameter name:

# let divide ~num ~den = num /. den;;
val divide : num:float -> den:float -> float = <fun>
# divide ~den:10.0 ~num:30.0;;
- : float = 3.

This is described under function definition here.



Answered By - Jeffrey Scofield
Answer Checked By - David Marino (PHPFixing Volunteer)

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.