So I've got two functions that based on their types, I feel like I should be able to combine with function composition.
ghci> :t show
show :: Show a => a -> String
ghci> :t putStrLn
putStrLn :: String -> IO ()
An initial attempt was successful,
ghci> ( putStrLn . show ) "Hello World!"
"Hello World!"
I figured I'd try defining a new function as that composition
ghci> let myShow = putStrLn . show
But it didn't work:
ghci> myShow "Hello World!"
<interactive>:28:8:
Couldn't match expected type `()' with actual type `[Char]'
In the first argument of `myShow', namely `"Hello World!"'
In the expression: myShow "Hello World!"
In an equation for `it': it = myShow "Hello World!"
Interestingly, the type of my myShow
function became () -> IO ()
ghci> :t myShow
myShow :: () -> IO ()
I had assumed that the type would have been Show a => a -> IO ()
.
Does anyone know why this attempt at function composition failed?
(I realize that this is probably a pretty basic question, but I'm just getting started with the language, so bear with me here)