Is there a possible way to rewrite this in a single line through the use of Monads?
input <- getLine
let parsed = reads input :: [(Int,String)]
I could not understand how I can pass input,
my attemp would be thinking about lambda notation.
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.
Another place for
fmap! Usefmapto change a value or values inside something else – in this case, insidegetLine, but it’s more widely useful.or with
import Data.Functororimport Control.Applicativeyou could write this asThe compiler might well be able to deduce you mean
Intfrom elsewhere, in which case you could omit the explicit type signature.fmapis a very very useful function indeed to know. You could read more in this other answer about fmap where I ended up writing a mini tutorial.Actually, if you’re interested in clean ways of writing one-liners, then you should find out more about Applicative Functors.