Advertisement
Guest User

Untitled

a guest
May 6th, 2025
24
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Racket 0.83 KB | None | 0 0
  1. #lang typed/racket
  2.  
  3. ;; No `cast` or `inst` needed.
  4.  
  5. (: functional (-> (U (-> Symbol Boolean)
  6.                      (-> Symbol Char))
  7.                   (-> Symbol String)))
  8.  
  9. (define (functional prc)
  10.   (lambda (smb)
  11.     (let ((obj (prc smb)))
  12.       (cond ((boolean? obj)
  13.              (if obj "1" "0"))
  14.             ((char? obj)
  15.              (string obj))))))
  16.  
  17. ;; Both `cast` and `inst` needed.
  18.  
  19. (: hashish (-> (U (HashTable Symbol Boolean)
  20.                   (HashTable Symbol Char))
  21.                (HashTable Symbol String)))
  22.  
  23. (define (hashish hsh)
  24.   ((inst hash-map/copy Symbol (U Boolean Char) Symbol String)
  25.    (cast hsh (HashTable Symbol (U Boolean Char)))
  26.    (lambda (smb obj)
  27.      (cond ((boolean? obj)
  28.             (values smb (if obj "1" "0")))
  29.            ((char? obj)
  30.             (values smb (string obj)))))))
  31.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement