[racket] Is there a type for a string with length 1?
Sorry I hit reply instead of reply all.
The docs say that all KeyEvents are strings, but not all strings are KeyEvents.
The definition of key-event? says that a key-event is either a string with length 1 or a member of KEY-EVTS.
(define (key-event? k)
(and (string? k) (or (= (string-length k) 1) (pair? (member k KEY-EVTS)))))
KEY-EVTS includes the things like “left” etc.
I was planning on doing something like this:
(define-type KeyEvent
(U String-with-length-1
“left”
“right”
“up”
“down”
...))
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.
On May 4, 2014, at 7:54 PM, dfeltey at ccs.neu.edu wrote:
> According to the docs at http://docs.racket-lang.org/teachpack/2htdpuniverse.html?q=type#%28tech._world._keyevent%29 a KeyEvent is just a string. How will you treat keyevents like "left" or "up" in your typed version?
>
> 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.
>
> Dan
>
>
> ----- Original Message -----
> From: "Alexander D. Knauth" <alexander at knauth.org>
> To: "Racket Users" <users at racket-lang.org>
> Sent: Sunday, May 4, 2014 7:35:17 PM GMT -05:00 US/Canada Eastern
> Subject: [racket] Is there a type for a string with length 1?
>
> Is there a type for a string with length 1?
> 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.
>
>
> ____________________
> Racket Users list:
> http://lists.racket-lang.org/users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20140504/edc1ee43/attachment.html>