Browse thread
cyclic types
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | sejourne_kevin <sejourne_kevin@y...> |
| Subject: | Re: [Caml-list] cyclic types |
Xavier Leroy a écrit :
>>For now I have setteled for
>> type forest = Forest of forest StringMap.t
>
>
> This is a very reasonable thing to do. That, or compile with -rectypes.
>
>
>>Can you give an example of why rectypes by default is dangerous?
>
>
> Recursive types don't break type soundness and are handled fine by the
> OCaml typechecker -- objects and variants use them in an essential way.
>
> The "danger" is that they cause obviously wrong code to pass
> type-checking and receive "impossible" recursive types, so you notice
> the problem not at the point of definition of the bad code, but at
> point of use. A simplified example is this:
>
> let f x = x :: x
>
> where the author of that code really intended
>
> let f x = x @ x
>
> With -rectypes, the wrong definition (with ::) is accepted with type
>
> val f : ('a list as 'a) -> 'a list = <fun>
>
> and it's only when you try to apply f to a "normal" list that the
> problem arises, with a hard-to-understand error message:
>
> f [1;2;3];;
> ^
> This expression has type int but is here used with type 'a list as 'a
>
> - Xavier Leroy
It should be nice this kind of explanations is available in the
documentation of the compiler rather than on a mailing list.
Kévin