caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Leo White <lpw25@cam.ac.uk>
To: Matej Kosik <5764c029b688c1c0d24a2e97cd764f@gmail.com>
Cc: OCaml <caml-list@inria.fr>
Subject: Re: [Caml-list] strange typechecking result
Date: 22 Feb 2013 18:33:33 +0000	[thread overview]
Message-ID: <Prayer.1.3.5.1302221833330.26859@hermes-1.csi.cam.ac.uk> (raw)
In-Reply-To: <5127AFD7.5040002@gmail.com>

On Feb 22 2013, Matej Kosik wrote:

>Hello,
>
>For one of my modules, the typechecker started to raise strange 
>complaints. I was not able to figure out exactly why, but at least I 
>wanted to narrow down the problem.
>
>This small program:
>
>   type r1 = {l1 : unit list}
>
>   and r2 = {l2 : int64 list}
>
>   let rec f1 _ =
>     ()
>
>   and _ r1 =
>     f1 r1.l1
>
>   and _ r2 =
>     f1 r2.l2
>
>is rejected by the typechecker with a following error message:
>
>   File "test.ml", line 12, characters 5-10:
>   Error: This expression has type int64 list
>          but an expression was expected of type unit list
>
>I do not understand why the given program was rejected.
>

I think that by default recursive uses of a function are monomorphic. You 
can fix this with an explicit polymorphic annotation:

   let rec f1: 'a. 'a -> unit = fun _ -> ()
   
   and f2 r1 = 
     f1 r1.l1
   
   and f3 r2 = 
     f1 r2.l2;;

Regards,

Leo


  reply	other threads:[~2013-02-22 18:33 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-02-22 17:50 Matej Kosik
2013-02-22 18:33 ` Leo White [this message]
2013-02-22 20:14   ` Matej Kosik
2013-02-22 21:06     ` Leo White
2013-02-22 23:09       ` Jeff Meister

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Prayer.1.3.5.1302221833330.26859@hermes-1.csi.cam.ac.uk \
    --to=lpw25@cam.ac.uk \
    --cc=5764c029b688c1c0d24a2e97cd764f@gmail.com \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).