3 ms·
Haskell can do these practical things quite easily. import Data.Char changeThird (a:b:c:rest) = a : b : map toUpper c : rest main = do cont
by mightybyte 13y ago
Haskell can do these practical things quite easily.
import Data.Char
changeThird (a:b:c:rest) = a : b : map toUpper c : rest
main = do
contents <- readFile "foo.txt"
let ls = lines contents
ws = map (changeThird . words) ls
writeFile "foo2.txt" (unlines $ map unwords ws)
But like others said, I think you're going to have a harder time if you try to learn Haskell by starting this way. Anyone learning Haskell will be coming in with no exposure to any other pure language, and that has big implications. There is a fundamental difference between the "contents <- readFile ..." line above and the next two lines that you have never encountered before in any other language. You'll probably have a pretty difficult time with it if you don't understand a little more about how the readFile function is different from the lines function and what that means for how you can use them. You can't just mindlessly copy examples from small day to day tasks like you can with other languages because Haskell is unlike any other language you know.
Please don't read the above paragraph to mean that Haskell is not suitable for these kinds of small tasks. I actually think that Haskell makes a fantastic scripting language. I'm just saying that you can't learn it like you learn other scripting languages. You need to get a bigger understanding of what's going on otherwise you'll end up frustrated about why things don't work the way you expect.
All that being said, I still HIGHLY recommend learning Haskell.