Replies: 1 comment 3 replies
-
Does this suffice? ---@generic T
---@param f fun(param1: T, param2: T, ...: T): T?
---@param ... T
---@return T?
local function bind(f, ...) end |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi there, I'm seeing if I can implement a version of Haskell's
bind
operator for theMaybe
monad but in Lua. I have a function that takes in some number of parameters, sayf
has typefun(param1: T1, param2: T2, ...): T?
, i.e.f
takes in some number of parametersT1, ..., Tn
(the number of which is unknown) and returns some optional typeT?
. I'm essentially writing an evaluate functionbind(f, ...)
that uses the arguments of...
and passes them intof
, returning the result.Is there a way to use annotations to force
...
to be the same arguments/type asf
's input? In other words,...
should have typeT1?, T2?, ..., Tn?
. Furthermore,bind
should have return typeT?
, the same asf
.Beta Was this translation helpful? Give feedback.
All reactions