DEV Community

Discussion on: Actually, callbacks are fine

Collapse
 
masaeedu profile image
Asad Saeeduddin • Edited

Hi Pablo. What currying is doing for this code is turning an impure function of type (ignoring errors for simplicity):

// :: (Username, Password, { userInfo: UserInfo, roles: Roles } -!-> Undefined) -!-> Undefined

, which is not a monadic value, into a pure function of the type:

// :: Username -> Password -> ({ userInfo: UserInfo, roles: Roles } -!-> Undefined) -!-> Undefined

for which the return type ({ userInfo: UserInfo, roles: Roles } -!-> Undefined) -!-> Undefined (and more generally, the type (a -!-> r) -!-> r) forms a monad.

We're changing our perspective so that all of our impure functions of multiple arguments can instead be interpreted as pure functions that accept one less argument and return an impure, callback-accepting computation with possibility of failure.