When the user inputs number m = 0, the program will never stop counting. Is there any way how to take care of that? so if the user inputs 0 the program will end.
import Control.Monad (replicateM)
transpose :: [[a]]->[[a]]
transpose ([]:_) = []
transpose x = (map head x) : transpose (map tail x)
.
.
.
You missed a case in transpose that is triggered by entering 0:
transpose :: [[a]]->[[a]]
transpose [] = []
transpose ([]:_) = []
transpose x = (map head x) : transpose (map tail x)
And the above is quite dangerous, as 'head' and 'tail' might fail:
transpose [[0],[]]
[[0,* Exception: Prelude.head: empty list
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With