Skip to content

Instantly share code, notes, and snippets.

@ELLIOTTCABLE
Last active May 20, 2022 20:04
Show Gist options
  • Save ELLIOTTCABLE/8cf51f2af70dca62fcdcf7bc9fef0ea4 to your computer and use it in GitHub Desktop.
Save ELLIOTTCABLE/8cf51f2af70dca62fcdcf7bc9fef0ea4 to your computer and use it in GitHub Desktop.
let smth ?(m=5) ?(n=5) ?(o=5) ~p = m+n+o+p
let with_z_instead : z:int -> (?m:int -> ?n:int -> 'a) -> 'a = fun ~z fn ->
fn ~m:z ~n:z
let _ =
let first = smth ~m:1 ~n:2 (* no ~o *) ~p:3 in
let second = with_z_instead ~z:4 smth (* no ~o *) ~p:123 in
(first, second)
(*
494 | let second = with_z_instead ~z:4 smth (* no ~o *) ~p:123 in
^^^^
Error: This expression has type ?m:int -> ?n:int -> ?o:int -> p:int -> int
but an expression was expected of type ?m:int -> ?n:int -> p:'a -> 'b
Type ?o:int -> p:int -> int is not compatible with type p:'a -> 'b
*)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment