caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Insufficient polymorphism in local let.
@ 2012-03-23  4:58 David Brown
  2012-03-23  5:12 ` Gabriel Scherer
  0 siblings, 1 reply; 2+ messages in thread
From: David Brown @ 2012-03-23  4:58 UTC (permalink / raw)
  To: caml-list

I'm trying to figure out how to get 'lmust' in 'get2' in the code
below to work.  It seems that it's type is being inferred as

   string -> string option -> string

instead of

   string -> 'a option -> 'a

The 'must' definition keeps it's polymorphism, as seen in 'get1'.  Is
there some way I can annotate the definition of 'lmust' so that it
will work?  Lifting 'lmust' out of 'get2' doesn't seem to help.

Thanks,
David

let must section name = function
   | Some o -> o
   | None -> 
     Printf.eprintf "Expecting %s in %s\n%!" name section;
     exit 1

type foo = { a: string; b: int }

let get1 a b =
   { a = must "get1" "a" a;
     b = must "get1" "b" b }

let get2 a b =
   (* This isn't polymorphic enough. *)
   let lmust = must "get2" in
   { a = lmust "a" a;
     b = lmust "b" b }

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2012-03-23  5:12 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-03-23  4:58 [Caml-list] Insufficient polymorphism in local let David Brown
2012-03-23  5:12 ` Gabriel Scherer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).