* [Caml-list] strange typechecking result
@ 2013-02-22 17:50 Matej Kosik
2013-02-22 18:33 ` Leo White
0 siblings, 1 reply; 5+ messages in thread
From: Matej Kosik @ 2013-02-22 17:50 UTC (permalink / raw)
To: OCaml
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.
Thanks in advance for any help.
--
Matej Kosik
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Caml-list] strange typechecking result
2013-02-22 17:50 [Caml-list] strange typechecking result Matej Kosik
@ 2013-02-22 18:33 ` Leo White
2013-02-22 20:14 ` Matej Kosik
0 siblings, 1 reply; 5+ messages in thread
From: Leo White @ 2013-02-22 18:33 UTC (permalink / raw)
To: Matej Kosik; +Cc: OCaml
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
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Caml-list] strange typechecking result
2013-02-22 18:33 ` Leo White
@ 2013-02-22 20:14 ` Matej Kosik
2013-02-22 21:06 ` Leo White
0 siblings, 1 reply; 5+ messages in thread
From: Matej Kosik @ 2013-02-22 20:14 UTC (permalink / raw)
To: OCaml
On 22/02/13 18:33, Leo White wrote:
>>
>
> 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
>
Yuri, Leo, thanks.
Now I see that there is even simpler program, that demonstrates the problem:
let rec f1 _ =
()
and f2 (value:int) =
f1 value
and f3 (value:char) =
f1 value
The typechecker rejects it for similar reasons.
File "test.ml", line 8, characters 5-10:
Error: This expression has type char but an expression
was expected of type int.
That's quite strange.
I would like to ask:
- Where is that restriction explained?
(I've searched Ocaml reference manual for "monomorphic" but nothing
relevant seemed to come up)
- Where are things like:
'a. 'a -> unit
described?
I've already seen it in some document, but now I fail
to find it again.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Caml-list] strange typechecking result
2013-02-22 20:14 ` Matej Kosik
@ 2013-02-22 21:06 ` Leo White
2013-02-22 23:09 ` Jeff Meister
0 siblings, 1 reply; 5+ messages in thread
From: Leo White @ 2013-02-22 21:06 UTC (permalink / raw)
To: Matej Kosik; +Cc: OCaml
>I would like to ask:
>
>- Where is that restriction explained?
> (I've searched Ocaml reference manual for "monomorphic" but nothing
> relevant seemed to come up)
>
>- Where are things like:
>
> 'a. 'a -> unit
>
> described?
>
I'm not sure if the restriction is explained anywhere but the solution is
described in:
http://caml.inria.fr/pub/docs/manual-ocaml-4.00/manual021.html#toc79
Regards,
Leo
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Caml-list] strange typechecking result
2013-02-22 21:06 ` Leo White
@ 2013-02-22 23:09 ` Jeff Meister
0 siblings, 0 replies; 5+ messages in thread
From: Jeff Meister @ 2013-02-22 23:09 UTC (permalink / raw)
To: Leo White; +Cc: Matej Kosik, OCaml
[-- Attachment #1: Type: text/plain, Size: 1101 bytes --]
As I understand it, polymorphic recursive functions require type
annotations because inferring their types is undecidable in the general
case.
On Fri, Feb 22, 2013 at 1:06 PM, Leo White <lpw25@cam.ac.uk> wrote:
> I would like to ask:
>>
>> - Where is that restriction explained?
>> (I've searched Ocaml reference manual for "monomorphic" but nothing
>> relevant seemed to come up)
>>
>> - Where are things like:
>>
>> 'a. 'a -> unit
>>
>> described?
>>
>>
> I'm not sure if the restriction is explained anywhere but the solution is
> described in:
>
> http://caml.inria.fr/pub/docs/**manual-ocaml-4.00/manual021.**html#toc79<http://caml.inria.fr/pub/docs/manual-ocaml-4.00/manual021.html#toc79>
>
> Regards,
>
> Leo
>
>
> --
> Caml-list mailing list. Subscription management and archives:
> https://sympa.inria.fr/sympa/**arc/caml-list<https://sympa.inria.fr/sympa/arc/caml-list>
> Beginner's list: http://groups.yahoo.com/group/**ocaml_beginners<http://groups.yahoo.com/group/ocaml_beginners>
> Bug reports: http://caml.inria.fr/bin/caml-**bugs<http://caml.inria.fr/bin/caml-bugs>
>
[-- Attachment #2: Type: text/html, Size: 1836 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2013-02-22 23:09 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-02-22 17:50 [Caml-list] strange typechecking result Matej Kosik
2013-02-22 18:33 ` Leo White
2013-02-22 20:14 ` Matej Kosik
2013-02-22 21:06 ` Leo White
2013-02-22 23:09 ` Jeff Meister
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox