[Haskell-cafe] On to applicative
michael rice
nowgate at yahoo.com
Sat Sep 4 14:06:54 EDT 2010
The two myAction functions below seem to be equivalent and, for this small case, show an interesting economy of code, but being far from a Haskell expert, I have to ask, is the first function as small (code wise) as it could be?
Michael
import Control.Applicative
data Color
= Red
| Blue
| Green
| Yellow
| Orange
| Brown
| Black
| White
deriving (Show, Read, Eq, Enum, Ord, Bounded)
-- myAction :: IO Color
-- myAction = getLine
-- >>= \str -> return (read str :: Color)
myAction :: IO Color
myAction = read <$> getLine
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20100904/de37724c/attachment.html
More information about the Haskell-Cafe
mailing list