IO question

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

IO question

Mike Houghton
I have

 input <- readFile “data.txt”
 let  input’ = splitOn “,” input
….

How do I make that into just one line?

Thanks

Mike
_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: IO question

David McBride
splitOn "," <$> readFile "data.txt"

or perhaps

readFile "data.txt" >>= return . splitOn ","

On Mon, Dec 11, 2017 at 3:56 PM, mike h <[hidden email]> wrote:
I have

 input <- readFile “data.txt”
 let  input’ = splitOn “,” input
….

How do I make that into just one line?

Thanks

Mike
_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: IO question

Mike Houghton
Thank you David.  Before posting I tried readFile "data.txt" >>= … but got errors as I didn’t use return.!! 

Mike


On 11 Dec 2017, at 21:00, David McBride <[hidden email]> wrote:

splitOn "," <$> readFile "data.txt"

or perhaps

readFile "data.txt" >>= return . splitOn ","

On Mon, Dec 11, 2017 at 3:56 PM, mike h <[hidden email]> wrote:
I have

 input <- readFile “data.txt”
 let  input’ = splitOn “,” input
….

How do I make that into just one line?

Thanks

Mike
_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners

_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: IO question

Vale Cofer-Shabica
In reply to this post by Mike Houghton
Just to add to David's answer, when I find myself in situations like:
foo >>= return . bar

hlint helpfully suggests:
fmap bar foo

So you could also have:
fmap (splitOn ",") $ readFile "data.txt"

-vale

--
vale cofer-shabica
401.267.8253

On Mon, Dec 11, 2017 at 4:24 PM, mike h <[hidden email]> wrote:
Thank you David.  Before posting I tried readFile "data.txt" >>= … but got errors as I didn’t use return.!! 

Mike



On 11 Dec 2017, at 21:00, David McBride <[hidden email]> wrote:

splitOn "," <$> readFile "data.txt"

or perhaps

readFile "data.txt" >>= return . splitOn ","

On Mon, Dec 11, 2017 at 3:56 PM, mike h <[hidden email]> wrote:
I have

 input <- readFile “data.txt”
 let  input’ = splitOn “,” input
….

How do I make that into just one line?

Thanks

Mike
_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners

_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners



_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: IO question

Vale Cofer-Shabica
I now, of course, feel silly because <$> is the infix version of fmap; apologies for list-spamming.

-vale

--
vale cofer-shabica
401.267.8253

On Tue, Dec 12, 2017 at 1:41 PM, Vale Cofer-Shabica <[hidden email]> wrote:
Just to add to David's answer, when I find myself in situations like:
foo >>= return . bar

hlint helpfully suggests:
fmap bar foo

So you could also have:
fmap (splitOn ",") $ readFile "data.txt"

-vale

--
vale cofer-shabica
<a href="tel:(401)%20267-8253" value="+14012678253" target="_blank">401.267.8253

On Mon, Dec 11, 2017 at 4:24 PM, mike h <[hidden email]> wrote:
Thank you David.  Before posting I tried readFile "data.txt" >>= … but got errors as I didn’t use return.!! 

Mike



On 11 Dec 2017, at 21:00, David McBride <[hidden email]> wrote:

splitOn "," <$> readFile "data.txt"

or perhaps

readFile "data.txt" >>= return . splitOn ","

On Mon, Dec 11, 2017 at 3:56 PM, mike h <[hidden email]> wrote:
I have

 input <- readFile “data.txt”
 let  input’ = splitOn “,” input
….

How do I make that into just one line?

Thanks

Mike
_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners

_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners




_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: IO question

Thomas Jakway
In reply to this post by Vale Cofer-Shabica
Personally I prefer <$> (infix fmap) to fmap, but is this confusing to beginners?

On Dec 12, 2017 10:42 AM, "Vale Cofer-Shabica" <[hidden email]> wrote:
Just to add to David's answer, when I find myself in situations like:
foo >>= return . bar

hlint helpfully suggests:
fmap bar foo

So you could also have:
fmap (splitOn ",") $ readFile "data.txt"

-vale

--
vale cofer-shabica
<a href="tel:(401)%20267-8253" value="+14012678253" target="_blank">401.267.8253

On Mon, Dec 11, 2017 at 4:24 PM, mike h <[hidden email]> wrote:
Thank you David.  Before posting I tried readFile "data.txt" >>= … but got errors as I didn’t use return.!! 

Mike



On 11 Dec 2017, at 21:00, David McBride <[hidden email]> wrote:

splitOn "," <$> readFile "data.txt"

or perhaps

readFile "data.txt" >>= return . splitOn ","

On Mon, Dec 11, 2017 at 3:56 PM, mike h <[hidden email]> wrote:
I have

 input <- readFile “data.txt”
 let  input’ = splitOn “,” input
….

How do I make that into just one line?

Thanks

Mike
_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners

_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners



_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: IO question

David McBride
In reply to this post by Vale Cofer-Shabica
No worries.  I definitely should have mentioned fmap and <$> are the same.

On Tue, Dec 12, 2017 at 1:43 PM, Vale Cofer-Shabica <[hidden email]> wrote:
I now, of course, feel silly because <$> is the infix version of fmap; apologies for list-spamming.

-vale

--
vale cofer-shabica
<a href="tel:(401)%20267-8253" value="+14012678253" target="_blank">401.267.8253

On Tue, Dec 12, 2017 at 1:41 PM, Vale Cofer-Shabica <[hidden email]> wrote:
Just to add to David's answer, when I find myself in situations like:
foo >>= return . bar

hlint helpfully suggests:
fmap bar foo

So you could also have:
fmap (splitOn ",") $ readFile "data.txt"

-vale

--
vale cofer-shabica
<a href="tel:(401)%20267-8253" value="+14012678253" target="_blank">401.267.8253

On Mon, Dec 11, 2017 at 4:24 PM, mike h <[hidden email]> wrote:
Thank you David.  Before posting I tried readFile "data.txt" >>= … but got errors as I didn’t use return.!! 

Mike



On 11 Dec 2017, at 21:00, David McBride <[hidden email]> wrote:

splitOn "," <$> readFile "data.txt"

or perhaps

readFile "data.txt" >>= return . splitOn ","

On Mon, Dec 11, 2017 at 3:56 PM, mike h <[hidden email]> wrote:
I have

 input <- readFile “data.txt”
 let  input’ = splitOn “,” input
….

How do I make that into just one line?

Thanks

Mike
_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners

_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners




_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners



_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners