Posts

Showing posts with the label Applicative

Can Someone Explain Where Applicative Instances Arise In This Code?

Answer : This is the Applicative instance for ((->) r) , functions from a common type. It combines functions with the same first argument type into a single function by duplicating a single argument to use for all of them. (<$>) is function composition, pure is const , and here's what (<*>) translates to: s :: (r -> a -> b) -> (r -> a) -> r -> b s f g x = f x (g x) This function is perhaps better known as the S combinator. The ((->) r) functor is also the Reader monad, where the shared argument is the "environment" value, e.g.: newtype Reader r a = Reader (r -> a) I wouldn't say it's common to do this for the sake of making functions point-free, but in some cases it can actually improve clarity once you're used to the idiom. The example you gave, for instance, I can read very easily as meaning "is a character a letter or number". You get instances of what are called static arrows (see "A...