<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><meta http-equiv="Content-Type" content="text/html charset=windows-1252"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div>Sorry I hit reply instead of reply all. </div><div><br></div><div>The docs say that all KeyEvents are strings, but not all strings are KeyEvents. </div><div>The definition of key-event? says that a key-event is either a string with length 1 or a member of KEY-EVTS. </div><div><div>(define (key-event? k) </div><div> (and (string? k) (or (= (string-length k) 1) (pair? (member k KEY-EVTS)))))</div></div><div>KEY-EVTS includes the things like “left” etc.</div><div>I was planning on doing something like this:</div><div><font face="Courier New">(define-type KeyEvent</font></div><div><font face="Courier New"> (U String-with-length-1</font></div><div><font face="Courier New"> “left”</font></div><div><font face="Courier New"> “right”</font></div><div><font face="Courier New"> “up”</font></div><div><font face="Courier New"> “down”</font></div><div><font face="Courier New"> ...))</font></div><div>I don’t want to use the Char type (or something like (U Char “left” “right” …)) because I want all of the key handlers etc. that worked for the big-bang from 2htdp/universe to work for my version. </div><br><div><div>On May 4, 2014, at 7:54 PM, <a href="mailto:dfeltey@ccs.neu.edu">dfeltey@ccs.neu.edu</a> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">According to the docs at <a href="http://docs.racket-lang.org/teachpack/2htdpuniverse.html?q=type#%28tech._world._keyevent%29">http://docs.racket-lang.org/teachpack/2htdpuniverse.html?q=type#%28tech._world._keyevent%29</a> a KeyEvent is just a string. How will you treat keyevents like "left" or "up" in your typed version?<br><br>There is a Char type, but would rule out things like "left", "right", "up", "down". You could just use String as your type and define constructors that ensure the string passed in is actually a KeyEvent.<br><br>Dan<br><br><br>----- Original Message -----<br>From: "Alexander D. Knauth" <<a href="mailto:alexander@knauth.org">alexander@knauth.org</a>><br>To: "Racket Users" <<a href="mailto:users@racket-lang.org">users@racket-lang.org</a>><br>Sent: Sunday, May 4, 2014 7:35:17 PM GMT -05:00 US/Canada Eastern<br>Subject: [racket] Is there a type for a string with length 1?<br><br>Is there a type for a string with length 1? <br>The reason is that I’m trying to make my own typed version of big-bang and I want to make a type for KeyEvent. <br><br><br>____________________<br> Racket Users list:<br> <a href="http://lists.racket-lang.org/users">http://lists.racket-lang.org/users</a><br></blockquote></div><br></div></body></html>