isAlphaNum :: Char -> Bool
isAlphaNum = (||) <$> isAlpha <*> isNum
I can see that it works, but I don’t understand where the instances of Applicative (or Functor) come from.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
This is the
Applicativeinstance 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 isconst, and here’s what(<*>)translates to:This function is perhaps better known as the S combinator.
The
((->) r)functor is also theReadermonad, where the shared argument is the “environment” value, e.g.: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”.