Course map
Haskell // 19

Strings and MisoString

Read

String is a list

String is [Char], so every list function works on it: length, reverse, map toUpper, take 3. words and unwords split and join on spaces; lines and unlines on newlines.

import Data.Char (toUpper)

main :: IO ()
main = do
  putStrLn (reverse "miso")                     -- osim
  print (words "a tasty framework")             -- ["a","tasty","framework"]
  putStrLn (unwords (map (map toUpper) (words "hello there")))
  print (show 42 ++ "!")                        -- "42!"

show turns a value into a String; read goes the other way (read "42" :: Int). ++ joins strings because they are lists.

01 / 05