Hi all,

Writing TR code, I find that the more I use the Option type, the more I want 
something like Haskell’s Maybe monad. Is there any existing tool I’m missing, 
that provides for applying functions to values of type (Option x), by 
propagating failures?

If not, would it be sensible to include such a thing in one of the TR packages 
as a standard TR library?

Unfortunately, I haven’t figured out a way to write a variable-arity version: 
This fails, presumably because TR’s occurrence typing is (quite understandably) 
not able to do much with ormap:

(: maybe-apply (All (a b) ((a * -> (Option b)) (Option a) * -> (Option b))))
(define (maybe-apply f . vs)
  (if (ormap not vs) #f (apply f vs)))

Error:
Type Checker: Bad arguments to function in `apply':
Domain: a *
Arguments: (Listof (U False a)) *
 in: (apply f vs)

But even having a trio of unary/binary/ternary versions would be very helpful. 
I’ve put up a tiny and crude library here 
<https://github.com/RenaissanceBug/option-bind>, but imagine there’s a better 
way to bring it into the racket ecosystem. Thoughts?

Cheers,
jmj

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to