* [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
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