Loading ...
Sorry, an error occurred while loading the content.

7027Re: "ocaml_beginners"::[] Type mismatch but why?

Expand Messages
  • Christian Lerrahn
    Jan 4, 2007
      Hi Jonathan,
      I feel stupid but I didn't understand your remedy. I tried to
      explicitly state the type of my optional argument but the error stayed
      the same. Would you mind writing out what you explained? I just seem to
      be too stupid to figure out a verbal explanation. ;-)

      Cheers,
      Christian

      Am Fri, 5 Jan 2007 16:29:42 +1300
      schrieb "Jonathan Roewen" <jonathan.roewen@...>:

      > It's because your optional argument can't be erased, confusing the
      > type checker.
      >
      > Adding an explicit type (foo list) to newghostparts,
      >
      > Expecting function has type ?newghostparts:foo list -> foo list
      > This argument cannot be applied without label
      >
      > Adding the label ~newghostparts to newlist in final line:
      >
      > Warning X: this optional argument cannot be erased.
      > let rec newgparticles opart ghostptcls ?(newghostparts = [opart]) =
      > ^^^^^^^
      > val newgparticles : foo -> foo list -> ?newghostparts:foo list -> foo
      > list = <fun>
      >
      > I've never quite fully understood labels. Perhaps the fully applied
      > function doesn't need labels thing doesn't apply to optional arguments
      > -- which seems a shame.
      >
      > Anyways, the workaround is to label the optional argument. And to
      > eliminate the warning, either change the order so it's not at the end,
      > or add a dummy argument to the end (unit).
      >
      > Jonathan
      >
      > On 1/5/07, Christian Lerrahn <ocaml@...> wrote:
      > > Hi,
      > > I have this snippet of code that drives me crazy. I just don't see
      > > why my types are mismatching. It's rather ugly code anyway but I
      > > couldn't think of a nice way of putting it so far. The error I get
      > > is
      > >
      > > # Characters 107-578:
      > > ....match (ghostptcls) with
      > > [] -> newghostparts
      > > | (gp :: gplist) -> let newgp = { r = gp; v = opart.v; ... } in
      > > let newlist = newgp :: newghostparts in newgparticles opart
      > > gplist newlist..
      > > This expression has type Particle.properties list but is here
      > > used with type Particle.properties list -> Particle.properties list
      > >
      > > The code is
      > >
      > > (* creates new ghostparticles *)
      > > let rec newgparticles opart ghostptcls ?(newghostparts = [opart]) =
      > > match (ghostptcls) with
      > > [] -> newghostparts
      > > | (gp :: gplist) -> let newgp = { r = gp; v = opart.v; ... } in
      > > let newlist = newgp :: newghostparts in newgparticles opart gplist
      > > newlist
      > >
      > > (* wrapper for ghostparticles routine in Vectorop *)
      > > let get_ghostparticles ~particle:particle =
      > > let list_of_ghostparticles = Vectorop.ghostparticle_loc
      > > particle.r in newgparticles particle list_of_ghostparticles []
      > >
      > > opart should be a single particle of type Particle.properties.
      > >
      > > Any hints what I am doing wrong?
      > >
      > > TIA,
      > > Christian
      > >
      > >
      > > Archives up to November 11, 2006 are also downloadable at
      > > http://www.connettivo.net/cntprojects/ocaml_beginners/ The archives
      > > of the very official ocaml list (the seniors' one) can be found at
      > > http://caml.inria.fr Attachments are banned and you're asked to be
      > > polite, avoid flames etc. Yahoo! Groups Links
      > >
      > >
      > >
      > >
    • Show all 5 messages in this topic