简体   繁体   中英

How can <*> accept functions in a context with a large number of parameters in Haskell?

<*> 函数具有 Applicative f => f (a -> b) -> fa - > fb 类型,但它可以在具有大量参数的上下文中取函数的第一个参数 (f (a - >b->c)) 是的,有柯里化,但为什么haskell 接受这一点?

Yeah, currying.

This works because there's no such thing as a function with multiple arguments in the first place. A->B->C is technically speaking the type of functions with a single argument of type A . The result of those functions happens to be again a function type, B->C , but the first <*> doesn't care about that. The next <*> may care about it and bind the B argument as well, but that's a separate step.

Yes, there is currying

and that's quite literally all there is to it.

A function of type a -> b -> c is in fact of type a -> (b -> c) - the two are completely equivalent, because of currying.

So the signature of <*> is Applicative f => f (a -> b) -> fa - > fb , as you say. But if b is also a function type, say c -> d , then this can be, as a specialisation:

Applicative f => f (a -> c -> d) -> f a - > f (c -> d)

and so on if it turns out that d above is in fact itself a function type.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM