avoid to print empty string

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

avoid to print empty string

Damien Mattei-2
i have this in a Monad IO:

 forM_ fltrdNamesBDs $ \(name,bdSidonie,bdWDS) ->
          if (bdWDS /= bdSidonie)
          then
             putStrLn $  name ++ " " ++ (show (bdSidonie :: Maybe Float)) ++ " " ++ show (bdWDS :: Maybe Float) ++ " " ++ show (bdWDS == bdSidonie)
          else
             putStr ""

is there a way to remove the silly putStr "" that output an empty string, i tried with when.... but as when return Nothing in case of False it fails to compile


_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.
Reply | Threaded
Open this post in threaded view
|

Re: avoid to print empty string

Brandon Allbery
You want:
  return ()

(Look at the type of putStrLn.)

On Mon, Jan 21, 2019 at 2:49 PM Damien Mattei <[hidden email]> wrote:
i have this in a Monad IO:

 forM_ fltrdNamesBDs $ \(name,bdSidonie,bdWDS) ->
          if (bdWDS /= bdSidonie)
          then
             putStrLn $  name ++ " " ++ (show (bdSidonie :: Maybe Float)) ++ " " ++ show (bdWDS :: Maybe Float) ++ " " ++ show (bdWDS == bdSidonie)
          else
             putStr ""

is there a way to remove the silly putStr "" that output an empty string, i tried with when.... but as when return Nothing in case of False it fails to compile

_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.


--
brandon s allbery kf8nh

_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.
Reply | Threaded
Open this post in threaded view
|

Re: avoid to print empty string

MarLinn
In reply to this post by Damien Mattei-2


i have this in a Monad IO:

 forM_ fltrdNamesBDs $ \(name,bdSidonie,bdWDS) ->
          if (bdWDS /= bdSidonie)
          then
             putStrLn $  name ++ " " ++ (show (bdSidonie :: Maybe Float))
++ " " ++ show (bdWDS :: Maybe Float) ++ " " ++ show (bdWDS == bdSidonie)
          else
             putStr ""

is there a way to remove the silly putStr "" that output an empty string, i
tried with when.... but as when return Nothing in case of False it fails to
compile


I don't see the problem with when? This (in the expanded version) doesn't work?

	forM_ fltrdNamesBDs $ \(name,bdSidonie,bdWDS) -> when (bdWDS /= bdSidonie) $ showStuff name bdSidonie bdWDS

As an extra remark, whenever I want to output a whole bunch of stuff in a row like this, I like to refactor into a concat, just to make the code more readable. If I can factor out the types, all the better:

	where
	    showStuff :: String -> Maybe Float -> Maybe Float -> IO ()
	    showStuff name bdSidonie bdWDS = putStrLn $ concat [name," ",show bdSidonie," ",show bdWDS," False"]

Or even

	    showStuff :: String -> Maybe Float -> Maybe Float -> IO ()
	    showStuff name bdSidonie bdWDS = putStrLn $ Data.List.intercalate " " [name,show bdSidonie,show bdWDS,show False]


Cheers.


_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.