Is it possible to make those two lines one line:
main = do line <- getLine
let result = words line
what I mean is something like non monadic code
result = words getLine
which — in my opinion — would improve readability.
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.
Try this:
result <- fmap words getLinefmaptakes a function with a type likea -> band turns it intof a -> f bfor anything that’s an instance ofFunctor, which should include allMonadinstances.There’s an equivalent function called
liftMthat’s specific toMonad, for murky historical reasons. You might need to use that instead in some cases, but for standard monads likeIOyou can stick withfmap.You can also import
Data.FunctororControl.Applicativeto get a nice operator version offmap, so you could writewords <$> getLineinstead, which often looks prettier.