Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the ((->) r) mean in instance Applicative ((->) r) where?

Tags:

haskell

instance Applicative ((->) r) where

This is the implementation of the Applicative typeclass for a function in Haskell. I don't really understand the ((->) r) and how to read it.

I think it means it is a function that takes one parameter and returns anything (another curried function, a String) but I'm not sure, is that right. Would that not be (r ->)

like image 707
atreeon Avatar asked Oct 21 '25 14:10

atreeon


1 Answers

Here, -> is a type-level operator; it takes two types and returns a new type (the function type). In ((->) r, it's partially applied, so you can think of it as a type-level function that takes one type a and returns the type of functions that take an r and returns an a.

((->) r) a == (->) r a  -- function application is left-associative
           == r -> a    -- switch to infix notation

You could say (r ->), except Haskell doesn't support type-level sections. (And I don't think there is a GHC extension to enable such support.)

There isn't really a good way to read it, because it exists at a level of abstraction that isn't talked about commonly enough to merit a natural language description.

like image 66
chepner Avatar answered Oct 23 '25 09:10

chepner



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!