<p>I'm confused, Sam. Is the example with the indirect struct less problematic somehow? Or should it be failing?</p>
<p>Carl Eastlund</p>
<p>--<br>
WARNING! Poorly-typed cell phone email precedes.</p>
<div class="gmail_quote">On Apr 11, 2013 7:23 AM, "Sam Tobin-Hochstadt" <<a href="mailto:samth@ccs.neu.edu">samth@ccs.neu.edu</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
The reason this doesn't work is that non-regular datatypes require<br>
significantly more algorithmic complexity to avoid non-termination/be<br>
correct. In particular, I don't know of a subtyping algorithm for<br>
non-regular datatypes.<br>
<br>
Sam<br>
<br>
On Thu, Apr 11, 2013 at 12:58 AM, Eric Dobson <<a href="mailto:eric.n.dobson@gmail.com">eric.n.dobson@gmail.com</a>> wrote:<br>
> So it looks like that you need an indirection struct, here is a simple example.<br>
><br>
> #lang typed/racket<br>
><br>
><br>
> (struct: (a) Indirect ((v : (Deep a))))<br>
> (struct: (a) Deep ((spine : (Indirect (List a)))))<br>
> ;(struct: (a) Deep ((spine : (Deep (List a)))))<br>
><br>
> The uncommented version typechecks, but the commented one does not. I<br>
> understand why this works in the implementation, but don't know the<br>
> theoretical reason why the implementation prevents it, since Indirect<br>
> and Deep should be isomorphic.<br>
><br>
> On Wed, Apr 10, 2013 at 9:43 PM, Eric Dobson <<a href="mailto:eric.n.dobson@gmail.com">eric.n.dobson@gmail.com</a>> wrote:<br>
>> Quick answer is to replace<br>
>> (define-type (Fingertree a) (U Empty (Single a) (Deep a)))<br>
>> With<br>
>> (struct: (a) Fingertree ((v : (U Empty (Single a) (Deep a)))))<br>
>><br>
>> Still looking into understanding what is going on, but I believe you<br>
>> will need to introduce a Rec somewhere to get it how you want.<br>
>><br>
>> On Wed, Apr 10, 2013 at 6:27 PM, Anthony Carrico <<a href="mailto:acarrico@memebeam.org">acarrico@memebeam.org</a>> wrote:<br>
>>> I've been reading about fingertrees, and I figure the best way to<br>
>>> understand is to implement. This is my first experience with typed<br>
>>> racket. Are nested datatypes supported?<br>
>>><br>
>>> This is my first try:<br>
>>><br>
>>> typed-fingertree.rkt:19:48: Type Checker: Structure type constructor<br>
>>> Deep applied to non-regular arguments ((U (Node2 a) (Node3 a)))<br>
>>><br>
>>> #lang typed/racket<br>
>>><br>
>>> (struct: (a) Digit1 ((v0 : a)))<br>
>>> (struct: (a) Digit2 ((v0 : a) (v1 : a)))<br>
>>> (struct: (a) Digit3 ((v0 : a) (v1 : a) (v2 : a)))<br>
>>> (struct: (a) Digit4 ((v0 : a) (v1 : a) (v2 : a) (v3 : a)))<br>
>>> (define-type (Digit a) (U (Digit1 a) (Digit2 a) (Digit3 a) (Digit4 a)))<br>
>>><br>
>>> (struct: (a) Node2 ((v0 : a) (v1 : a)))<br>
>>> (struct: (a) Node3 ((v0 : a) (v1 : a) (v2 : a)))<br>
>>> (define-type (Node a) (U (Node2 a) (Node3 a)))<br>
>>><br>
>>> (struct: Empty ())<br>
>>> (struct: (a) Single ((v : a)))<br>
>>> (struct: (a) Deep ((left : (Digit a))<br>
>>> (spine : (Fingertree (Node a)))<br>
>>> (right : (Digit a))))<br>
>>><br>
>>> (define-type (Fingertree a) (U Empty (Single a) (Deep a)))<br>
>>><br>
>>> Thank you!<br>
>>><br>
>>> --<br>
>>> Anthony Carrico<br>
>>><br>
>>><br>
>>> ____________________<br>
>>> Racket Users list:<br>
>>> <a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/users</a><br>
>>><br>
> ____________________<br>
> Racket Users list:<br>
> <a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/users</a><br>
____________________<br>
Racket Users list:<br>
<a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/users</a><br>
<br>
</blockquote></div>