Learning OCaml, and wondering why the compiler thinks I'm providing zero arguments to a one-argument type constructor.
This OCaml:
open Core
module Json = Yojson.Safe.Util
type ticker = Ticker of string
let ticker_of_yojson s =
s |> Json.to_string |> Ticker |> Result.Ok
produces this error:
The constructor Ticker expects 1 argument(s)
but is applied here to 0 argument(s).
If I change it to this, wrapping the constructor calls in lambdas,
let ticker_of_yojson s =
s |> Json.to_string |> (fun x -> Ticker x) |> (fun x -> Result.Ok x)
it compiles. If I only wrap the Ticker
constructor call in a lambda, I get the same zero arguments error regarding Result.Ok
.
What is the compiler missing here that substituting with the lambdas resolves? Is there something else I can add such that the original version without the lambdas works?
I saw this other SO post that seems like a similar problem, but I can't connect the dots between the two situations: ocaml type constructor arguments
Thanks for your time - any help appreciated.