meta (description ( 'Convert\sa\sUsed\stype\sinto\sa\sString. )) ; to-string := λ(: is-used IsUsed). (: ( (let r '_s) (match is-used ( () ( Used (set r 'Used_s) ) ( Unused (set r 'Unused_s) ) ( Return (set r 'Return_s) ) ( Tail (set r 'Tail_s) ) ( Call (set r 'Call_s) ) )) r ) String); to-string := λ(: tt Type). (: ( (let r (to-string-impl tt)) (clone-rope r) ) String); to-string := λ(: tt List). (: ( (let r SNil) (match tt ( () ( LEOF () ) ( (LCons( p1 LEOF )) (set r (to-string-impl p1)) ) ( (LCons( p1 rst )) ( (set r (SCons( (close(to-string rst)) (close(SCons( (close(SAtom ',_s)) (close(to-string-impl p1)) ))) ))) )) )) r ) S); to-string-impl := λ(: tt Type). (: ( (let r SNil) (match tt ( () ( TAny (set r (SAtom '?_s)) ) ( (TVar v) (set r (SAtom v)) ) ( (TAnd( lt rt )) ( (let ls (to-string-impl lt)) (let rs (to-string-impl rt)) (set r (SCons( (close ls) (close(SCons( (close(SAtom '+_s)) (close rs) ))) ))) )) ( (TGround( tag LEOF )) ( (set r (SAtom tag)) )) ( (TGround( '..._s (LCons( p1 LEOF )) )) ( (set r (SCons( (close r) (close(to-string-impl p1)) ))) (set r (SCons( (close r) (close(SAtom '..._s)) ))) )) ( (TGround( tag ps )) ( (set r (SAtom tag)) (set r (SCons( (close r) (close(SAtom '<_s)) ))) (set r (SCons( (close r) (close(to-string ps)) ))) (set r (SCons( (close r) (close(SAtom '>_s)) ))) )) )) r ) S);