[plt-scheme] Recursive types and their specification

From: Noel Welsh (noelwelsh at yahoo.com)
Date: Tue Aug 9 10:58:44 EDT 2005

Hi all,

I have what is really a general PL question, but I think
might illustrate one way in which Scheme's
un/uni/dynamically typed behaviour may be useful, so I'm
asking here.  I'm writing a little program to control
Pacman.  As a demo I have written the following FSM:

  (define (policy)
      (letrec
          ((down
            (lambda ()
              (values
               (e:make-down)
               (lambda ()
                 (if (< (random) 0.4)
                     (left)
                     (down))))))
           (left
            (lambda ()
              (values
               (e:make-left)
               (lambda ()
                 (if (< (random) 0.6)
                     (right)
                     (left))))))
           (right
            (lambda ()
              (values
               (e:make-right)
               (lambda ()
                 (if (< (random) 0.4)
                     (up)
                     (right))))))
           (up
            (lambda ()
              (values
               (e:make-up)
               (lambda ()
                 (if (< (random) 0.5)
                     (up)
                     (down)))))))
        (down)))

The FSM returns two values: the action to take (up, down,
left, or right) and the continuation for the policy.  How
does one specify the type of the continuation?  It's a
function that returns two values, the first of which is an
action, and the second of which is a function that returns
two values, the first of which...

Is this something that would cause HM to blow up (I think
so)?  Does this show that Scheme is the One True Way?  Does
asking this question mean I have to revoke my LtU
editorship (Ehud, I know you read this list :)?

Thanks,
Noel

Email: noelwelsh <at> yahoo <dot> com   noel <at> untyped <dot> com
AIM: noelhwelsh
Blogs: http://monospaced.blogspot.com/  http://www.untyped.com/untyping/


		
____________________________________________________
Start your day with Yahoo! - make it your home page 
http://www.yahoo.com/r/hs 
 



Posted on the users mailing list.