User loginNavigation |
archivesThe Type of a Recursive CombinatorThe latest Cat version ( 0.9.7 at http://www.cat-language.com/download.html ) now has a linear recursion combinator "rec". The Cat type inference algorithm currently can't handle self-referential functions, but you implement recursive algorithms using the rec combinator. Here is an example of the factorial program: >> define f { [dup 1 <=] [*] [pop 1] [dup --] rec } inferred type for program 'f' as ( int ) -> ( int ) main stack: _empty_ >> 5 f main stack: 120 >> 6 f main stack: 120 720 The type of the rec combinator is interesting (at least I thought so): ( (A:any*)->(A A) // argument relation (A)->(B:any*) // termination function (A B)->(B) // result relation (A)->(bool A) // termination condition A // input )->(B) I was wondering what people's thoughts were about the rec combinator? For example is it in fact interesting or novel to see the types explicitly stated for each component of linear recursion? Do you think there might be some educational value for students to have recursion explained in terms of arguments to a combinator? Any feedback would be very helpful, thanks in advance! Note: those familiar with Cat will notice that stack descriptions now read left to right, where the leftmost type corresponds to the top of the stack. Busy, busy, busyAs you can probably deduce from the lack of posts, I am extremely busy. Real life is taking its toll. I implore the other editors to take charge. |
Browse archivesActive forum topics |
Recent comments
22 weeks 8 hours ago
22 weeks 12 hours ago
22 weeks 12 hours ago
44 weeks 1 day ago
48 weeks 3 days ago
50 weeks 20 hours ago
50 weeks 20 hours ago
1 year 4 days ago
1 year 5 weeks ago
1 year 5 weeks ago