Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 4th, 2012  |  syntax: None  |  size: 0.57 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Can someone explain where Applicative instances arise in this code?
  2. isAlphaNum :: Char -> Bool
  3. isAlphaNum = (||) <$> isAlpha <*> isNum
  4.        
  5. s :: (r -> a -> b) -> (r -> a) -> r -> b
  6. s f g x = f x (g x)
  7.        
  8. newtype Reader r a = Reader (r -> a)
  9.        
  10. f <*> x = c -> (f c) (x c)
  11.        
  12. isAlphaNum c = (isAlpha c) || (isNum c)
  13.        
  14. import Data.Char
  15. import Control.Applicative
  16.  
  17. isAlphaNum = liftA2 (||) isAlpha isNumber
  18.        
  19. import Data.Char
  20. import Control.Monad
  21.  
  22. isAlphaNum = liftM2 (||) isAlpha isNumber
  23.        
  24. import Data.Function
  25.  
  26. orFst = (||) `on` fst
  27.  
  28. -- orFst (True,3) (False, 7)
  29. --> True