Hi!
I’m just starting out so please let me know if I’m doing anything particularly silly:
I have defined a function:
let try_next ~f s =
try Some (Stream.next s |> f)
with Stream.Failure -> None
;;
val try_next : f:('a -> 'b) -> 'a Stream.t -> 'b option = <fun>
But when I try to provide the identity function as a default for f
I find that the signature for the function changes; presumably because the type-checker can see that Fn.id
is of 'a -> 'a
:
let try_next ?(f=Fn.id) s =
try Some (Stream.next s |> f)
with Stream.Failure -> None
;;
val try_next : ?f:('a -> 'a) -> 'a Stream.t -> 'a option = <fun>
Even trying to supply my own signature (the original) is taken as a mismatch:
module StreamEx : sig
val try_next : ?f:('a -> 'b) -> 'a Stream.t -> 'b option
end = struct
let try_next ?(f=Fn.id) s =
try Some (Stream.next s |> f)
with Stream.Failure -> None
end
;;
Error: Signature mismatch:
...
Values do not match:
val try_next : ?f:('a -> 'a) -> 'a Stream.t -> 'a option
is not included in
val try_next : ?f:('a -> 'b) -> 'a Stream.t -> 'b option
Any help would be appreciated.