I want to create a function, that takes function as varying argument, the only thing i know about the funtion argument(which is a function itself) is they are wrapped in the same Monad....
myFunc :: forall arguments output m.
MonadEffect m
=> (arguments -> m output)
-> m (argument -> m output)
myFunc fn = do
-- getting function's name using FFI and other stuff...
pure fn
I'm able to write the function, when I explicitly specify the argument length like,
-- for function with ONE argument
myFunc1 :: forall argument1 output m
. MonadEffect m
=> (argument1 -> m output)
-> m (argument1 -> m output)
myFunc1 fn = do
-- do something
pure fn
-- for function with TWO argument
myFunc2 :: forall argument1 argument2 output m.
MonadEffect m =>
(argument1 -> argument2 -> m output) ->
m (argument1 -> argument2 -> m output)
myFunc2 fn = do
-- do something
pure fn
How can I write argument1 -> argument2 -> m output as argument -> m output in type level?
is there any type/Constraint that helps in doing so?
ps: I just want to understand whether it's possible
In Haskell, you can define type families that calculate the return type of a function:
and a type-level list of the types of its arguments (in reverse order):
This would allow you to write:
which would make available type variables
outputandargumentswithin the body of your function:This may or may not be suitable for what you're trying to do, and it may or may not work in Purescript.
Anyway, here's a self-contained Haskell example: