typessmlmlrecursive-datastructuresmutual-recursion

what is a mutually recursive type?


If in ML, an example of a recursive datatype is:

datatype llist = Nil | Node of int * llist

What is a mutually recursive datatype and whats an example of it, in ML?


Solution

  • One such example could be these stupid datatypes.

    datatype a = A | Ab of b
    and      b = B | Ba of a
    

    They make no sense, but they show that it is possible to use the and keyword (just as with functions) to reference something "ahead" which is normally not possible

    They are mutually (as they both...) recursive (...reference each other)